add "uplink" indicator
- currently shows ssid and signal strength, if wlan - for lan, should show interface name (not tested) plan to enhance with - lan speed, for wired ethernet - wwan support
This commit is contained in:
parent
da00b8a3a5
commit
229ba07b80
@ -3,6 +3,7 @@
|
||||
|
||||
(local iostream (require :iostream))
|
||||
(local metric (require :metric))
|
||||
(local uplink (require :uplink))
|
||||
|
||||
(stylesheet "licht.css")
|
||||
|
||||
@ -16,7 +17,6 @@
|
||||
; 0xf377 ; glyph not present in font-awesome free
|
||||
))
|
||||
|
||||
|
||||
(fn spawn []
|
||||
true)
|
||||
|
||||
@ -41,6 +41,25 @@
|
||||
{:text v})
|
||||
}))
|
||||
|
||||
(let [uplink (uplink.new)
|
||||
input (iostream.from-descriptor uplink.fd)]
|
||||
(indicator {
|
||||
:wait-for {
|
||||
:input [input]
|
||||
:interval (* 4 1000)
|
||||
}
|
||||
:refresh
|
||||
#(let [status (uplink:status)]
|
||||
(if status
|
||||
{:text (.. (or status.ssid status.name "?")
|
||||
" "
|
||||
(if status.quality
|
||||
(tostring (+ status.quality 100))
|
||||
""))}
|
||||
{:text "no internet"}
|
||||
))
|
||||
}))
|
||||
|
||||
(let [f (iostream.open "/tmp/statuspipe" :r)]
|
||||
(indicator {
|
||||
;; this is a guide to tell blinkenlicht when it might
|
||||
|
@ -1,16 +1,23 @@
|
||||
(local posix (require :posix))
|
||||
(local fcntl (require :posix.fcntl))
|
||||
|
||||
(fn from-descriptor [fd]
|
||||
{
|
||||
:read #(posix.unistd.read fd $2) ;XXX needs to check for eof
|
||||
:close #(posix.unistd.close fd)
|
||||
:fileno fd
|
||||
})
|
||||
|
||||
|
||||
(fn open [name direction]
|
||||
(let [flags (match direction
|
||||
:r posix.O_RDONLY
|
||||
:w (+ posix.O_WRONLY posix.O_CREAT))
|
||||
fd (posix.open name flags)]
|
||||
(fcntl.fcntl fd fcntl.F_SETFL fcntl.O_NONBLOCK)
|
||||
{
|
||||
:read #(posix.unistd.read fd $2) ;XXX needs to check for eof
|
||||
:close #(posix.unistd.close fd)
|
||||
:fileno fd
|
||||
}))
|
||||
(from-descriptor fd)))
|
||||
|
||||
{: open }
|
||||
{
|
||||
: open
|
||||
: from-descriptor
|
||||
}
|
||||
|
@ -58,8 +58,7 @@
|
||||
))
|
||||
event)
|
||||
|
||||
|
||||
(fn netlunk []
|
||||
(fn uplink []
|
||||
(let [links {}
|
||||
routes {}
|
||||
sock (nl.socket)]
|
||||
@ -83,17 +82,20 @@
|
||||
:refresh #(each [_ event (ipairs (sock:event))]
|
||||
(handle-event event))
|
||||
:fd (sock:fd)
|
||||
:uplink (fn [self]
|
||||
:status (fn [self]
|
||||
(self:refresh)
|
||||
(let [defaultroute routes.default
|
||||
interface (and defaultroute
|
||||
(. links defaultroute.index))]
|
||||
(and interface (= interface.running "yes")
|
||||
(get-network-info interface))))
|
||||
:wait #(sock:poll 1000)
|
||||
:interface (fn [self ifnum] (. links ifnum))
|
||||
:interface (fn [self ifnum]
|
||||
(. links ifnum))
|
||||
}
|
||||
))
|
||||
|
||||
(comment
|
||||
(let [nl (netlunk)]
|
||||
(while (or (nl:wait) true)
|
||||
(nl:refresh)
|
||||
@ -102,4 +104,8 @@
|
||||
(print "default route through " (view interface))
|
||||
nil
|
||||
(print "no default route")
|
||||
)))
|
||||
))))
|
||||
|
||||
{
|
||||
:new uplink
|
||||
}
|
Loading…
Reference in New Issue
Block a user