2023-03-11 23:52:47 +00:00
|
|
|
class Bar:
|
2023-03-12 00:36:22 +00:00
|
|
|
def __init__(self, seperator, margin):
|
2023-04-03 20:58:45 +00:00
|
|
|
self.monitors = {}
|
2023-03-12 00:36:22 +00:00
|
|
|
self.seperator = seperator
|
|
|
|
self.margin = margin
|
|
|
|
|
2023-04-03 20:58:45 +00:00
|
|
|
def add_monitor(self, monitor):
|
|
|
|
self.monitors[monitor] = { "left": [], "center": [], "right": [] }
|
|
|
|
|
|
|
|
def add_module(self, monitor, module):
|
2023-03-11 23:52:47 +00:00
|
|
|
match module.alignment:
|
|
|
|
case "left":
|
2023-04-03 20:58:45 +00:00
|
|
|
self.monitors[monitor]["left"].append(module)
|
2023-03-11 23:52:47 +00:00
|
|
|
case "center":
|
2023-04-03 20:58:45 +00:00
|
|
|
self.monitors[monitor]["center"].append(module)
|
2023-03-11 23:52:47 +00:00
|
|
|
case "right":
|
2023-04-03 20:58:45 +00:00
|
|
|
self.monitors[monitor]["right"].append(module)
|
2023-03-11 23:52:47 +00:00
|
|
|
|
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):
|
2023-04-03 20:58:45 +00:00
|
|
|
for monitor in self.monitors:
|
|
|
|
print("%{S" + str(monitor) + "}", end='')
|
|
|
|
print("%{l}" + self.margin, end='')
|
|
|
|
self.__print_alignment_group(self.monitors[monitor]["left"])
|
|
|
|
|
|
|
|
print("%{c}", end='')
|
|
|
|
self.__print_alignment_group(self.monitors[monitor]["center"])
|
2023-03-12 00:36:22 +00:00
|
|
|
|
2023-04-03 20:58:45 +00:00
|
|
|
print("%{r}", end='')
|
|
|
|
self.__print_alignment_group(self.monitors[monitor]["right"])
|
2023-03-12 00:36:22 +00:00
|
|
|
|
2023-04-03 20:58:45 +00:00
|
|
|
print(self.margin, end='')
|
2023-03-11 23:52:47 +00:00
|
|
|
|
2023-04-03 20:58:45 +00:00
|
|
|
print(flush=True)
|