eufon

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b84a8f5758840e462305b74348d9bc2ce683aea6
parent b0fe8e1dff2b3fa542e9241ebaa990e1650aa935
Author: Daniel Barlow <dan@telent.net>
Date:   Thu, 24 Mar 2022 12:13:17 +0000

add battery status indicator

Diffstat:
Mblinkenlicht/bl.fnl | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/blinkenlicht/bl.fnl b/blinkenlicht/bl.fnl @@ -7,6 +7,15 @@ (fn disk-free-percent [] 83) +(fn battery-status [path] + (let [name (.. (or path "/sys/class/power_supply/BAT0") "/uevent")] + (with-open [f (io.open name :r)] + (let [fields {}] + (each [line #(f:read "*l")] + (let [(name value) (line:match "([^=]+)=(.+)")] + (tset fields (: (name:gsub "_" "-") :lower) value))) + fields)))) + (fn spawn [] true) @@ -26,7 +35,12 @@ ;; :text #((f:read):sub 1 10) ;; })) (indicator { - :text "HI!" + :interval (* 10 1000) + :text #(let [{:power-supply-energy-full full + :power-supply-energy-now now} + (battery-status)] + (string.format "BAT %d%%" + (math.floor (* 100 (/ (tonumber now) (tonumber full)))))) }) (indicator { :interval 5000