2023-02-12 20:09:01 +00:00
|
|
|
from threading import Thread
|
|
|
|
from subprocess import run
|
|
|
|
from time import sleep
|
|
|
|
from config_parsing import get_validated_config, parse_module
|
|
|
|
|
|
|
|
running_modules_dict = {"left": {}, "center": {}, "right": {}}
|
|
|
|
|
|
|
|
def print_bar():
|
|
|
|
for alignment in running_modules_dict:
|
|
|
|
match alignment:
|
|
|
|
case "left":
|
|
|
|
print("%{l}", end="")
|
|
|
|
case "center":
|
|
|
|
print("%{c}", end="")
|
|
|
|
case "right":
|
|
|
|
print("%{r}", end="")
|
2023-03-11 03:14:30 +00:00
|
|
|
# convert group to list so we can access subsequent items
|
2023-03-11 03:08:50 +00:00
|
|
|
group = list(running_modules_dict[alignment].items())
|
2023-02-12 20:09:01 +00:00
|
|
|
for index, module in enumerate(group):
|
2023-03-11 03:08:50 +00:00
|
|
|
print(module[1], end="")
|
2023-03-11 03:14:30 +00:00
|
|
|
# IF module is not the last AND it has text
|
2023-03-11 03:08:50 +00:00
|
|
|
if index != (len(group) - 1) and len(module[1]) > 0:
|
2023-03-11 03:14:30 +00:00
|
|
|
# THEN only print seperator if the module is eventually followed
|
|
|
|
# by a module with text
|
2023-03-11 03:08:50 +00:00
|
|
|
for i in range(index + 1, len(group) - 1):
|
|
|
|
if len(group[i][1]) > 0:
|
|
|
|
print(seperator, end="")
|
|
|
|
break;
|
2023-02-12 20:09:01 +00:00
|
|
|
|
|
|
|
print(flush=True)
|
|
|
|
|
|
|
|
def create_module_string(pre, prefix, command, post):
|
|
|
|
cmd_output = run(command, shell=True, capture_output=True, text=True).stdout.strip()
|
2023-02-17 02:21:42 +00:00
|
|
|
if cmd_output != "":
|
|
|
|
return (pre + padding + prefix + cmd_output + padding + post)
|
|
|
|
else:
|
|
|
|
return cmd_output
|
2023-02-12 20:09:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
def new_module_thread(alignment, pre, name, prefix, command, post, refresh):
|
2023-02-12 21:54:06 +00:00
|
|
|
running_modules_dict[alignment][name] = ""
|
2023-02-12 20:09:01 +00:00
|
|
|
while True:
|
|
|
|
module_string = create_module_string(pre, prefix, command, post)
|
|
|
|
running_modules_dict[alignment][name] = module_string
|
|
|
|
print_bar()
|
2023-02-18 19:14:08 +00:00
|
|
|
if refresh == 0:
|
|
|
|
break
|
2023-02-12 20:09:01 +00:00
|
|
|
sleep(refresh/1000)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
global padding
|
|
|
|
global seperator
|
|
|
|
|
|
|
|
config = get_validated_config("./testing_config.yml")
|
|
|
|
padding = config["bar"]["config"]["padding"]
|
|
|
|
seperator = config["bar"]["config"]["seperator"]
|
|
|
|
|
|
|
|
|
|
|
|
modules = config["bar"]["modules"]
|
|
|
|
for module in modules:
|
|
|
|
parameters = parse_module(module)
|
|
|
|
# print(parameters)
|
|
|
|
|
|
|
|
x = Thread(target=new_module_thread, args=parameters)
|
|
|
|
x.start()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|