easyconf-lemonbar/easyconf_lemonbar/Bar.py

39 lines
1.1 KiB
Python
Raw Normal View History

2023-03-11 23:52:47 +00:00
class Bar:
2023-03-12 00:36:22 +00:00
def __init__(self, seperator, margin):
2023-03-11 23:52:47 +00:00
self.left = []
self.center = []
self.right = []
2023-03-12 00:36:22 +00:00
self.seperator = seperator
self.margin = margin
2023-03-11 23:52:47 +00:00
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)
2023-03-12 00:36:22 +00:00
def __print_alignment_group(self, alignment_group):
for index, module in enumerate(alignment_group):
2023-03-11 23:52:47 +00:00
print(module.text, end='')
2023-03-12 00:36:22 +00:00
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)
2023-03-11 23:52:47 +00:00
print("%{c}", end='')
2023-03-12 00:36:22 +00:00
self.__print_alignment_group(self.center)
2023-03-11 23:52:47 +00:00
print("%{r}", end='')
2023-03-12 00:36:22 +00:00
self.__print_alignment_group(self.right)
2023-03-11 23:52:47 +00:00
2023-03-12 00:36:22 +00:00
print(self.margin, flush=True)