38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
class Bar:
|
|
def __init__(self, seperator, margin):
|
|
self.left = []
|
|
self.center = []
|
|
self.right = []
|
|
|
|
self.seperator = seperator
|
|
self.margin = margin
|
|
|
|
def add_module(self, module):
|
|
match module.alignment:
|
|
case "left":
|
|
self.left.append(module)
|
|
case "center":
|
|
self.center.append(module)
|
|
case "right":
|
|
self.right.append(module)
|
|
|
|
def __print_alignment_group(self, alignment_group):
|
|
for index, module in enumerate(alignment_group):
|
|
print(module.text, end='')
|
|
if len(module.text) > 0:
|
|
for i in range(index+1, len(alignment_group)):
|
|
if len(alignment_group[i].text) > 0:
|
|
print(self.seperator, end='')
|
|
break
|
|
|
|
def print(self):
|
|
print("%{l}" + self.margin, end='')
|
|
self.__print_alignment_group(self.left)
|
|
|
|
print("%{c}", end='')
|
|
self.__print_alignment_group(self.center)
|
|
|
|
print("%{r}", end='')
|
|
self.__print_alignment_group(self.right)
|
|
|
|
print(self.margin, flush=True)
|