57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
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="")
|
|
group = running_modules_dict[alignment]
|
|
for index, module in enumerate(group):
|
|
print(group[module], end="")
|
|
if index != (len(group) - 1):
|
|
print(seperator, end="")
|
|
|
|
print(flush=True)
|
|
|
|
def create_module_string(pre, prefix, command, post):
|
|
cmd_output = run(command, shell=True, capture_output=True, text=True).stdout.strip()
|
|
return (pre + padding + prefix + cmd_output + padding + post)
|
|
|
|
|
|
def new_module_thread(alignment, pre, name, prefix, command, post, refresh):
|
|
while True:
|
|
module_string = create_module_string(pre, prefix, command, post)
|
|
running_modules_dict[alignment][name] = module_string
|
|
print_bar()
|
|
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()
|