-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmui.py
More file actions
97 lines (82 loc) · 4.49 KB
/
mui.py
File metadata and controls
97 lines (82 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# mui.py
class MUI:
def __init__(self, side_symbol='|', header_footer_symbol='-', corner_symbol='#', accent_symbol='%', padding=2, justify='left'):
justify_list = ['left', 'right']
if justify not in justify_list: self.JUSTIFY = 'left'
else: self.JUSTIFY = justify
if (not padding) or padding < 0: padding = 0
if not side_symbol: side_symbol = '|'
if not header_footer_symbol: header_footer_symbol = '-'
if not corner_symbol: corner_symbol = '+'
if not accent_symbol: accent_symbol = '#'
# fix corner-side relations in case of different length
while len(side_symbol) > len(corner_symbol): corner_symbol += corner_symbol[0]
while len(side_symbol) < len(corner_symbol): side_symbol += side_symbol[0]
# style variables in-class
self.SIDE_SYMBOL, self.HEADER_SYMBOL, self.CORNER_SYMBOL, self.ACCENT_SYMBOL, self.PADDING = (
side_symbol, header_footer_symbol, corner_symbol, accent_symbol, padding)
def _noname(self):
raise NameError('Name cannot be empty')
def mui_textbox(self, name):
if not name: self._noname()
# splitter and width + padding handler
lines = name.split('\n')
max_width = max(len(line) for line in lines)
padding = ' ' * self.PADDING
line_header = self.CORNER_SYMBOL + self.HEADER_SYMBOL * (max_width + 2 * self.PADDING) + self.CORNER_SYMBOL
# output block
print(line_header)
for line in lines:
spacing = (max_width - len(line)) * ' '
line_current = f"{self.SIDE_SYMBOL}{padding}{line}{spacing}{padding}{self.SIDE_SYMBOL}"
print(line_current)
print(line_header)
def mui_selector(self, name, options_list, use_counter = True):
if not name: self._noname()
if use_counter: counter_current = 0
if not use_counter: counter_current = False
# width, padding and condition handler
lines = name.split('\n')
max_width = max(len(line) for line in lines)
max_option_width = max(len(option) for option in options_list)
if use_counter: absolute_width = max(max_width, max_option_width) + 2 + len(str(len(options_list)))
else: absolute_width = max(max_width, max_option_width)
padding = ' ' * self.PADDING
line_header = self.CORNER_SYMBOL + self.HEADER_SYMBOL * (absolute_width + 2 * self.PADDING) + self.CORNER_SYMBOL
# output block
print(line_header) # first header line
for line in lines:
spacing = (absolute_width - len(line)) * ' '
if self.JUSTIFY == 'right': line_current = f"{self.SIDE_SYMBOL}{padding}{spacing}{line}{padding}{self.SIDE_SYMBOL}"
if self.JUSTIFY == 'left': line_current = f"{self.SIDE_SYMBOL}{padding}{line}{spacing}{padding}{self.SIDE_SYMBOL}"
print(line_current)
print(line_header) # separator between textbox and option box
for option in options_list:
if use_counter:
counter_current += 1
spacing_option = (absolute_width - len(option) - 2 - len(str(counter_current))) * ' '
if self.JUSTIFY == 'right': line_current_option =\
f"{self.SIDE_SYMBOL}{padding}{spacing_option}{counter_current}. {option}{padding}{self.SIDE_SYMBOL}"
if self.JUSTIFY == 'left': line_current_option =\
f"{self.SIDE_SYMBOL}{padding}{counter_current}. {option}{spacing_option}{padding}{self.SIDE_SYMBOL}"
print(line_current_option)
else:
spacing_option = (absolute_width - len(option)) * ' '
if self.JUSTIFY == 'left': line_current_option =\
f"{self.SIDE_SYMBOL}{padding}{option}{spacing_option}{padding}{self.SIDE_SYMBOL}"
if self.JUSTIFY == 'right': line_current_option =\
f"{self.SIDE_SYMBOL}{padding}{spacing_option}{option}{padding}{self.SIDE_SYMBOL}"
print(line_current_option)
print(line_header) # footer
def mui_p_line(self, line):
if not line: self._noname()
lines = line.split('\n')
for line in lines:
line = f"{self.ACCENT_SYMBOL * 2}{self.PADDING * ' '}{line}"
print(line)
def mui_line(self, line):
if not line: self._noname()
lines = line.split('\n')
for line in lines:
line = f"{self.ACCENT_SYMBOL}{self.PADDING * ' '}{line}{self.PADDING * ' '}{self.ACCENT_SYMBOL}"
print(line)