alignment works properly

This commit is contained in:
Noah Swerhun 2023-02-10 21:17:06 -06:00
parent 55f21b2180
commit dbfd6543bb
3 changed files with 94 additions and 27 deletions

View file

@ -13,22 +13,22 @@ bar:
offset: 0 # vertical offset of text in pixels. can be negative.
line_color: '#ff0000' # default underline color
modules: # bar modules
modules: # bar modules
time: # module name can be anything you want
command: 'date' # command to be run
refresh: 1000 # how often to refresh in milliseconds
bg_color: '#000' # color of the bar behind the text of this module
fg_color: '#FFF' # color of the text itself
align: left # left, right, or center
font: 'fontname' # the name of the font for this specific module
line:
type: underline # underline or overline
color: '#000' # line color
button:
activator: left # how to activate the button. clicks: left, right, middle. scroll wheel: scrup, scrdown
command: 'echo "hello" > ~/file.txt' # command to run when button is clicked
# you may have multiple buttons with different activators.
time: # module name can be anything you want
command: 'date' # command to be run
refresh: 1000 # how often to refresh in milliseconds
format:
bg_color: '#000' # color of the bar behind the text of this module
fg_color: '#FFF' # color of the text itself
align: left # left, right, or center.
font: 'fontname' # the name of the font for this specific module
line:
type: underline # underline or overline
color: '#000' # line color
button: # you may have multiple buttons with different activators.
activator: left # how to activate the button. clicks: left, right, middle. scroll wheel: scrup, scrdown
command: 'echo "hello" > ~/file.txt' # command to run when button is clicked
memory: # define multiple modules...
command: "free -h | awk '/Mem/ {print $3}'"

View file

@ -26,7 +26,7 @@ for item in lemonbar_cmd_options:
case 'fg_color':
lemonbar_command += (" -F '" + lemonbar_cmd_options['fg_color'] + "'")
case 'offset':
lemonbar_command += (" -o " + lemonbar_cmd_options['offset'])
lemonbar_command += (" -o " + str(lemonbar_cmd_options['offset']))
case 'line_color':
lemonbar_command += (" -U '" + lemonbar_cmd_options['line_color'] + "'")

View file

@ -4,31 +4,98 @@ from threading import Thread
from subprocess import run
from time import sleep
running_modules_dict = {}
running_modules_dict = {"left": {}, "center": {}, "right": {}}
def print_modules():
for module in running_modules_dict:
print(running_modules_dict[module] + " | ", end='')
for alignment in running_modules_dict:
match alignment:
case "left":
print("%{l}", end="")
case "center":
print("%{c}", end="")
case "right":
print("%{r}", end="")
for module in running_modules_dict[alignment]:
print(running_modules_dict[alignment][module], end="")
print(flush=True)
def module_thread(name, cmd, refresh, pre, post):
def new_module_thread(alignment, 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
running_modules_dict[alignment][name] = result
print_modules()
sleep(refresh/1000)
with open("./testing_config.yml", 'r', encoding='utf8') as file:
def parse_module(module):
cmd = module["command"]
refresh = module["refresh"]
pre = ""
post = ""
format_options = module["format"]
for option in format_options:
match option:
# Align is handled differently. See below.
# case "align":
case "offset":
pre += ("%{O" + str(format_options[option]) + "}")
case "bg_color":
pre += ("%{B" + format_options[option] + "}")
post += "%{B-}"
case "fg_color":
pre += ("%{F" + format_options[option] + "}")
post += "%{F-}"
case "font":
pre += ("%{T" + format_options[option] + "}")
post += "%{T-}"
case "line":
line_options = format_options[option]
for line_option in line_options:
match line_options:
case "type":
if line_options[line_option] == "underline":
pre += ("%{+u}")
post += ("%{-u}")
elif line_options[line_option] == "overline":
pre += ("%{+o}")
post += ("%{-o}")
case "color":
pre += ("%{U" + line_options[line_option] + "}")
post += "%{U-}"
case "button":
button_options = format_options[option]
button = 1
match button_options["activator"]:
case "left":
button = 1
case "middle":
button = 2
case "right":
button = 3
case "scrup":
button = 4
case "scrdown":
button = 5
pre += ("%{A" + str(button)+ ":" + button_options["command"] + ":}")
post += "%{A}"
return [cmd, refresh, pre, post]
with open("./testing_config.yml", "r", encoding="utf8") as file:
config_file = safe_load(file)
modules = config_file['bar']['modules']
modules = config_file["bar"]["modules"]
for module in modules:
cmd = modules[module]['command']
refresh = modules[module]['refresh']
parameters = parse_module(modules[module])
parameters.insert(0, module)
running_modules_dict[module] = ''
alignment = modules[module]["format"]["align"]
parameters.insert(0, alignment)
running_modules_dict[alignment][module] = ''
print(parameters)
x = Thread(target=module_thread, args=(module, cmd, refresh, '', ''))
x = Thread(target=new_module_thread, args=parameters)
x.start()