modules output correctly and can be read by lemonbar

This commit is contained in:
Noah Swerhun 2023-02-10 19:20:59 -06:00
parent 89fd0c84b5
commit 07e5d30764

View file

@ -4,14 +4,21 @@ from threading import Thread
from subprocess import run
from time import sleep
def module_thread(cmd, refresh, pre, post):
while True:
print(pre, end='')
cmd_output = run(cmd, shell=True, capture_output=True, text=True).stdout
print(cmd_output.strip(), end='')
print(post)
sleep(refresh/1000)
running_modules_dict = {}
def print_modules():
for module in running_modules_dict:
print(running_modules_dict[module] + " | ", end='')
print(flush=True)
def module_thread(name, cmd, refresh, pre, post):
while True:
result = pre
result += run(cmd, shell=True, capture_output=True, text=True).stdout.strip()
result += post
running_modules_dict[name] = result
print_modules()
sleep(refresh/1000)
with open("./testing_config.yml", 'r', encoding='utf8') as file:
config_file = safe_load(file)
@ -20,5 +27,8 @@ modules = config_file['bar']['modules']
for module in modules:
cmd = modules[module]['command']
refresh = modules[module]['refresh']
x = Thread(target=module_thread, args=(cmd, refresh, '', ''))
running_modules_dict[module] = ''
x = Thread(target=module_thread, args=(module, cmd, refresh, '', ''))
x.start()