alignment works properly
This commit is contained in:
parent
55f21b2180
commit
dbfd6543bb
3 changed files with 94 additions and 27 deletions
|
@ -18,17 +18,17 @@ bar:
|
||||||
time: # module name can be anything you want
|
time: # module name can be anything you want
|
||||||
command: 'date' # command to be run
|
command: 'date' # command to be run
|
||||||
refresh: 1000 # how often to refresh in milliseconds
|
refresh: 1000 # how often to refresh in milliseconds
|
||||||
|
format:
|
||||||
bg_color: '#000' # color of the bar behind the text of this module
|
bg_color: '#000' # color of the bar behind the text of this module
|
||||||
fg_color: '#FFF' # color of the text itself
|
fg_color: '#FFF' # color of the text itself
|
||||||
align: left # left, right, or center
|
align: left # left, right, or center.
|
||||||
font: 'fontname' # the name of the font for this specific module
|
font: 'fontname' # the name of the font for this specific module
|
||||||
line:
|
line:
|
||||||
type: underline # underline or overline
|
type: underline # underline or overline
|
||||||
color: '#000' # line color
|
color: '#000' # line color
|
||||||
button:
|
button: # you may have multiple buttons with different activators.
|
||||||
activator: left # how to activate the button. clicks: left, right, middle. scroll wheel: scrup, scrdown
|
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
|
command: 'echo "hello" > ~/file.txt' # command to run when button is clicked
|
||||||
# you may have multiple buttons with different activators.
|
|
||||||
|
|
||||||
memory: # define multiple modules...
|
memory: # define multiple modules...
|
||||||
command: "free -h | awk '/Mem/ {print $3}'"
|
command: "free -h | awk '/Mem/ {print $3}'"
|
||||||
|
|
|
@ -26,7 +26,7 @@ for item in lemonbar_cmd_options:
|
||||||
case 'fg_color':
|
case 'fg_color':
|
||||||
lemonbar_command += (" -F '" + lemonbar_cmd_options['fg_color'] + "'")
|
lemonbar_command += (" -F '" + lemonbar_cmd_options['fg_color'] + "'")
|
||||||
case 'offset':
|
case 'offset':
|
||||||
lemonbar_command += (" -o " + lemonbar_cmd_options['offset'])
|
lemonbar_command += (" -o " + str(lemonbar_cmd_options['offset']))
|
||||||
case 'line_color':
|
case 'line_color':
|
||||||
lemonbar_command += (" -U '" + lemonbar_cmd_options['line_color'] + "'")
|
lemonbar_command += (" -U '" + lemonbar_cmd_options['line_color'] + "'")
|
||||||
|
|
||||||
|
|
89
modules.py
89
modules.py
|
@ -4,31 +4,98 @@ from threading import Thread
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
running_modules_dict = {}
|
running_modules_dict = {"left": {}, "center": {}, "right": {}}
|
||||||
|
|
||||||
def print_modules():
|
def print_modules():
|
||||||
for module in running_modules_dict:
|
for alignment in running_modules_dict:
|
||||||
print(running_modules_dict[module] + " | ", end='')
|
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)
|
print(flush=True)
|
||||||
|
|
||||||
def module_thread(name, cmd, refresh, pre, post):
|
def new_module_thread(alignment, name, cmd, refresh, pre, post):
|
||||||
while True:
|
while True:
|
||||||
result = pre
|
result = pre
|
||||||
result += run(cmd, shell=True, capture_output=True, text=True).stdout.strip()
|
result += run(cmd, shell=True, capture_output=True, text=True).stdout.strip()
|
||||||
result += post
|
result += post
|
||||||
running_modules_dict[name] = result
|
running_modules_dict[alignment][name] = result
|
||||||
print_modules()
|
print_modules()
|
||||||
sleep(refresh/1000)
|
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)
|
config_file = safe_load(file)
|
||||||
|
|
||||||
modules = config_file['bar']['modules']
|
modules = config_file["bar"]["modules"]
|
||||||
for module in modules:
|
for module in modules:
|
||||||
cmd = modules[module]['command']
|
parameters = parse_module(modules[module])
|
||||||
refresh = modules[module]['refresh']
|
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()
|
x.start()
|
||||||
|
|
Loading…
Reference in a new issue