fix bat monitor
This commit is contained in:
parent
f71fed2884
commit
36c5ec22ae
3 changed files with 33 additions and 14 deletions
|
@ -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 [
|
||||||
|
|
|
@ -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 []
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue