From 2f32fac349ce8f5fd8aef49a115ced3bf5e951d8 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 26 Apr 2022 22:13:37 +0100 Subject: [PATCH] merge blinkenlicht, add modeline --- blinkenlicht/bl.fnl | 116 -------------------- blinkenlicht/{blinkenlicht.fnl => init.fnl} | 0 default.nix | 17 ++- fennelrun.lua | 4 + blinkenlicht/licht.css => modeline.css | 0 modeline.fnl | 52 +++++++++ rc.fnl | 4 +- 7 files changed, 73 insertions(+), 120 deletions(-) delete mode 100644 blinkenlicht/bl.fnl rename blinkenlicht/{blinkenlicht.fnl => init.fnl} (100%) create mode 100644 fennelrun.lua rename blinkenlicht/licht.css => modeline.css (100%) create mode 100644 modeline.fnl diff --git a/blinkenlicht/bl.fnl b/blinkenlicht/bl.fnl deleted file mode 100644 index c055fd3..0000000 --- a/blinkenlicht/bl.fnl +++ /dev/null @@ -1,116 +0,0 @@ -(local {: bar : indicator : stylesheet : run} (require :blinkenlicht)) - -(local {: view} (require :fennel)) - -(local iostream (require :iostream)) -(local modem (require :modem)) - -(local uplink (require :metric.uplink)) -(local battery (require :metric.battery)) -(local cpustat (require :metric.cpustat)) - -(stylesheet "licht.css") - -(fn battery-icon-codepoint [status percent] - (if (= status "Charging") 0xf0e7 - (> percent 90) 0xf240 ;full - (> percent 60) 0xf241 ;3/4 - (> percent 40) 0xf242 ;1/2 - (> percent 15) 0xf243 ;1/4 - (>= percent 0) 0xf244 ;empty - ; 0xf377 ; glyph not present in font-awesome free - )) - -(fn wlan-quality-class [quality] - (if (< -50 quality) "p100" - (< -67 quality) "p75" - (< -70 quality) "p50" - (< -80 quality) "p25" - "p0")) - -(fn spawn [] - true) - -(bar - { - ;; bar must be full width to set up an "exclusive zone" (moves - ;; other windows out of the way), otherwise it will display on - ;; to of whatever's on the screen already - :anchor [:top :right :left] - :orientation :horizontal - :gravity :end - :classes ["hey"] - :indicators - [ - (let [] - (var previous 0) - ;; on my laptop, adding this indicator has made the task - ;; go from ~ 1% cpu to around 3%, which is not ideal - (indicator { - :wait-for { :interval (* 1 500) } - :refresh - (let [stat (cpustat.new)] - #(let [current (. (stat:read) :iowait) - delta (- current previous) - v (if (> delta 4) "" " ")] - (set previous current) - {:text v})) - })) - - (indicator { - :wait-for { - :interval (* 4 1000) - } - :refresh - (let [modem (modem.new)] - #(let [{:m3gpp-operator-name operator - :signal-quality quality} (modem:read)] - {:text (.. operator - ;;" " (. quality 1) "dBm" - ) - })) - }) - - (let [uplink (uplink.new) - input (iostream.from-descriptor uplink.fd)] - (indicator { - :wait-for { - :input [input] - } - :refresh - #(let [status (uplink:read) - devtype status.devtype] - (if status - {:text (.. (or status.ssid status.name "?") - " ") - :classes [devtype - (and (= devtype "wlan") - (wlan-quality-class status.quality))] - } - {:text "no internet"} - )) - })) - - (indicator { - :wait-for { :interval (* 1000 10) } - :refresh - (let [battery (battery.new (or (os.getenv "BLINKEN_BATTERY") - "axp20x-battery"))] - #(let [{:power-supply-capacity percent - :power-supply-status status} - (battery.read) - icon-code (battery-icon-codepoint - status (tonumber percent))] - {:text - (string.format "%s %d%%" (utf8.char icon-code) percent) - :classes ["battery" (if (< (tonumber percent) 20) "low" "ok")] - })) - }) - (indicator { - :wait-for { :interval 4000 } - :refresh #{:text (os.date "%H:%M")} - }) - - ]}) - -(run) diff --git a/blinkenlicht/blinkenlicht.fnl b/blinkenlicht/init.fnl similarity index 100% rename from blinkenlicht/blinkenlicht.fnl rename to blinkenlicht/init.fnl diff --git a/default.nix b/default.nix index d0fa895..b95556d 100644 --- a/default.nix +++ b/default.nix @@ -1,19 +1,30 @@ { stdenv , callPackage , fennel +, gobject-introspection +, gtk3 +, gtk-layer-shell , lua5_3 } : let fennel_ = (fennel.override { lua = lua5_3; }); luaWithPackages = lua5_3.withPackages (ps: with ps; [ (toLuaModule fennel_) - busted + lgi + luaposix ]); - kiwmi = callPackage ./kiwmi.nix { lua = luaWithPackages; }; + kiwmi = callPackage ./kiwmi.nix { lua = lua5_3; }; in stdenv.mkDerivation { pname = "eufon"; version = "0.1"; - buildInputs = [ luaWithPackages kiwmi ]; + buildInputs = [ + luaWithPackages + kiwmi + gobject-introspection.dev + gtk-layer-shell + gtk3 + ]; + src = ./.; } diff --git a/fennelrun.lua b/fennelrun.lua new file mode 100644 index 0000000..e373427 --- /dev/null +++ b/fennelrun.lua @@ -0,0 +1,4 @@ +local fennel = require("fennel") +table.insert(package.loaders or package.searchers, fennel.searcher) +-- print(fennel.view(arg)) +fennel.dofile(arg[0]) diff --git a/blinkenlicht/licht.css b/modeline.css similarity index 100% rename from blinkenlicht/licht.css rename to modeline.css diff --git a/modeline.fnl b/modeline.fnl new file mode 100644 index 0000000..488aff1 --- /dev/null +++ b/modeline.fnl @@ -0,0 +1,52 @@ +(local {: bar : indicator : stylesheet : run} (require :blinkenlicht)) + +(local {: view} (require :fennel)) + +(local iostream (require :blinkenlicht.iostream)) +;(local modem (require :blinkenlicht.modem)) + +;(local uplink (require :blinkenlicht.metric.uplink)) +;(local battery (require :blinkenlicht.metric.battery)) +(local cpustat (require :blinkenlicht.metric.cpustat)) + +(stylesheet "licht.css") + +(fn battery-icon-codepoint [status percent] + (if (= status "Charging") 0xf0e7 + (> percent 90) 0xf240 ;full + (> percent 60) 0xf241 ;3/4 + (> percent 40) 0xf242 ;1/2 + (> percent 15) 0xf243 ;1/4 + (>= percent 0) 0xf244 ;empty + ; 0xf377 ; glyph not present in font-awesome free + )) + +(fn wlan-quality-class [quality] + (if (< -50 quality) "p100" + (< -67 quality) "p75" + (< -70 quality) "p50" + (< -80 quality) "p25" + "p0")) + +(fn spawn [] + true) + +(bar + { + ;; bar must be full width to set up an "exclusive zone" (moves + ;; other windows out of the way), otherwise it will display on + ;; to of whatever's on the screen already + :anchor [:top :right :left] + :orientation :horizontal + :gravity :end + :classes ["hey"] + :indicators + [ + (indicator { + :wait-for { :interval 4000 } + :refresh #{:text (os.date "%H:%M")} + }) + + ]}) + +(run) diff --git a/rc.fnl b/rc.fnl index 9038d26..7f8404e 100644 --- a/rc.fnl +++ b/rc.fnl @@ -1,4 +1,6 @@ (kiwmi:on "output" #(doto $1 (: :set_mode 360 720 0))) -(kiwmi:spawn "swaybg -c '#ff00ff'") + +;(kiwmi:spawn "swaybg -c '#ff00ff'") +(kiwmi:spawn "lua -l fennelrun modeline.fnl") (kiwmi:spawn "foot")