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 ] { def main [ path: string ] {
loop { loop {
print (get_and_format $path)
sleep $DELAY;
}
}
def get_and_format [ path: string ] {
let fract = get_bat_charge_fraction $path; let fract = get_bat_charge_fraction $path;
let is_charging = get_bat_charging_status $path; let is_charging = get_bat_charging_status $path;
let percent = ($fract * 100) | math round; let percent = ($fract * 100) | math round;
print $"<span foreground=\"#d65d0e\">(get_bat_icon $fract $is_charging)</span> ($percent)<span foreground=\"#7c6f64\">%</span>"; return $"<span foreground=\"#d65d0e\">(get_bat_icon $fract $is_charging)</span> ($percent)<span foreground=\"#7c6f64\">%</span>";
sleep 2sec;
}
} }
def get_bat_charge_fraction [ def get_bat_charge_fraction [

View file

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

View file

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