modules output correctly and can be read by lemonbar
This commit is contained in:
parent
89fd0c84b5
commit
07e5d30764
1 changed files with 18 additions and 8 deletions
26
modules.py
26
modules.py
|
@ -4,14 +4,21 @@ from threading import Thread
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
def module_thread(cmd, refresh, pre, post):
|
running_modules_dict = {}
|
||||||
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)
|
|
||||||
|
|
||||||
|
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:
|
with open("./testing_config.yml", 'r', encoding='utf8') as file:
|
||||||
config_file = safe_load(file)
|
config_file = safe_load(file)
|
||||||
|
@ -20,5 +27,8 @@ modules = config_file['bar']['modules']
|
||||||
for module in modules:
|
for module in modules:
|
||||||
cmd = modules[module]['command']
|
cmd = modules[module]['command']
|
||||||
refresh = modules[module]['refresh']
|
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()
|
x.start()
|
||||||
|
|
Loading…
Reference in a new issue