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 ] {
|
||||
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 [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue