fix bat monitor

This commit is contained in:
Schrottkatze 2025-03-20 17:56:42 +01:00
parent f71fed2884
commit 36c5ec22ae
Signed by: schrottkatze
SSH key fingerprint: SHA256:FPOYVeBy3QP20FEM42uWF1Wa/Qhlk+L3S2+Wuau/Auo
3 changed files with 33 additions and 14 deletions

View file

@ -15,15 +15,41 @@ const ICONS = [
[ 󰁹 󰂅 ]
];
const DELAY = 2sec;
def "main auto" [] {
loop {
let paths = ls "/sys/class/power_supply"
| each {|it| $it.name | path basename}
| filter {|it| $it starts-with "BAT"};
if ($paths | is-not-empty) {
let result = $paths
| each {|it| get_and_format $it}
| prepend ""
| str join "|";
print $result
} else {
print ""
}
sleep $DELAY;
}
}
def main [ path: string ] {
loop {
print (get_and_format $path)
sleep $DELAY;
}
}
def get_and_format [ path: string ] {
let fract = get_bat_charge_fraction $path;
let is_charging = get_bat_charging_status $path;
let percent = ($fract * 100) | math round;
print $"<span foreground=\"#d65d0e\">(get_bat_icon $fract $is_charging)</span> ($percent)<span foreground=\"#7c6f64\">%</span>";
sleep 2sec;
}
return $"<span foreground=\"#d65d0e\">(get_bat_icon $fract $is_charging)</span> ($percent)<span foreground=\"#7c6f64\">%</span>";
}
def get_bat_charge_fraction [

View file

@ -1,10 +1,6 @@
(deflisten bat0
(deflisten bat
:initial "<span foreground=\"#cc241d\">BAT0 ERR</span>"
{ "~/.config/eww/scripts/bat.nu BAT0"}
)
(deflisten bat1
:initial "<span foreground=\"#cc241d\">BAT1 ERR</span>"
{ "~/.config/eww/scripts/bat.nu BAT1"}
{ "~/.config/eww/scripts/bat.nu auto"}
)
(defwidget cpu []

View file

@ -27,10 +27,7 @@
(cpu)
(sep)
(mem)
(sep)
(label :markup bat0)
(sep)
(label :markup bat1)
(label :markup bat)
)
(box
:halign "center"