eufon

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

commit ba54bd7e4184c2d1a1e6d4f75399aef3ccb38533
parent e198e8aae5b3d277f4f05fbe66a4108f2037031a
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 25 Mar 2022 11:21:21 +0000

extract "system info" functions into new metric.fnl module

Diffstat:
Mblinkenlicht/README.md | 9+++++----
Mblinkenlicht/bl.fnl | 23+++++------------------
Ablinkenlicht/metric.fnl | 21+++++++++++++++++++++
3 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/blinkenlicht/README.md b/blinkenlicht/README.md @@ -17,9 +17,9 @@ Not quite dogfood-ready yet, but fast approaching. * blinkenlicht.fnl is the module that parses `bar` and `indicator` forms and does all the UI -* also in bl.fnl but needs extracting to a home of its own, all the - glue that looks up load average, wifi signal strength, time of day - etc for indicators to use +* metric.fnl is a collection of functions that read metrics (load + average, battery status etc) from the system, for indicators to + display. Use the `default.nix` for guidance as to libraries and other setup required - or just use it, of course. @@ -44,7 +44,8 @@ Gtk will find it anyway. Magic. * [ ] allow height customisation * [ ] add some mechanism for indicators that wait for events instead of polling * [ ] set poll interval based on indicators' requested intervals -* [ ] set indicator background colour (use css for this?) +* [X] set indicator background colour (use css for this?) +* [ ] allow indicator to change styles based on status ```fennel diff --git a/blinkenlicht/bl.fnl b/blinkenlicht/bl.fnl @@ -1,22 +1,9 @@ (local {: bar : indicator : stylesheet : run} (require :blinkenlicht)) +(local {: view} (require :fennel)) -(stylesheet "licht.css") - -(fn loadavg [] - (with-open [f (io.open "/proc/loadavg" :r)] - (tonumber (: (f:read "*a") :match "[0-9.]+" )))) +(local metric (require :metric)) -(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)))) +(stylesheet "licht.css") (fn battery-icon-codepoint [status percent] (if ; (= status "Charging") 0xf376 ; glyph not present in font-awesome free @@ -41,7 +28,7 @@ [ (indicator { :interval 200 - :icon #(if (> (loadavg) 2) "face-sad" "face-smile") + :icon #(if (> (metric.loadavg) 2) "face-sad" "face-smile") }) ;; (let [f (io.open "/tmp/statuspipe" "r")] ;; (indicator { @@ -53,7 +40,7 @@ :classes ["yellow"] :text #(let [{:power-supply-energy-full full :power-supply-energy-now now - :power-supply-status status} (battery-status) + :power-supply-status status} (metric.battery) percent (math.floor (* 100 (/ (tonumber now) (tonumber full)))) icon-code (battery-icon-codepoint status percent)] (string.format "%s %d%%" (utf8.char icon-code) percent)) diff --git a/blinkenlicht/metric.fnl b/blinkenlicht/metric.fnl @@ -0,0 +1,21 @@ +(local {: view} (require :fennel)) + + +(fn loadavg [] + (with-open [f (io.open "/proc/loadavg" :r)] + (let [line (f:read "*a") + (one five fifteen) (line:match "([%d.]+) +([%d.]+) +([%d.]+)")] + (values (tonumber one) (tonumber five) (tonumber fifteen))))) + +(print (loadavg)) + +(fn battery [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)))) + +{ : loadavg : battery }