added pingclock and clear input
This commit is contained in:
parent
117ba68d89
commit
8bf1a1e381
5 changed files with 157 additions and 28 deletions
|
@ -2,7 +2,6 @@ import std/os
|
||||||
import std/json
|
import std/json
|
||||||
import std/rdstdin
|
import std/rdstdin
|
||||||
import marshal
|
import marshal
|
||||||
import argparse
|
|
||||||
|
|
||||||
type
|
type
|
||||||
i3BarData* = object
|
i3BarData* = object
|
||||||
|
@ -49,6 +48,9 @@ proc parseInput*(): i3BarInput =
|
||||||
return i3input
|
return i3input
|
||||||
except:
|
except:
|
||||||
return i3BarInput()
|
return i3BarInput()
|
||||||
|
proc clearInput*(count: int = 1) =
|
||||||
|
for x in countup(0, count):
|
||||||
|
discard readLineFromStdin("")
|
||||||
|
|
||||||
proc getArguments*(): seq[string] =
|
proc getArguments*(): seq[string] =
|
||||||
let args = commandLineParams()
|
let args = commandLineParams()
|
||||||
|
|
|
@ -3,6 +3,7 @@ import strutils
|
||||||
import std/osproc
|
import std/osproc
|
||||||
import std/math
|
import std/math
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
|
import std/threadpool
|
||||||
|
|
||||||
proc getLimit(): int
|
proc getLimit(): int
|
||||||
|
|
||||||
|
@ -30,9 +31,12 @@ proc getDesign(pcnt: float): string =
|
||||||
let text = icon & " " & $percent & "%"
|
let text = icon & " " & $percent & "%"
|
||||||
return text
|
return text
|
||||||
|
|
||||||
proc getBrightness() =
|
proc get_brightness(run_once: bool = false) =
|
||||||
|
var last_pcnt: float = 0
|
||||||
|
while true:
|
||||||
let current = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/actual_brightness")))
|
let current = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/actual_brightness")))
|
||||||
let pcnt = (current/limit)*100
|
let pcnt = (current/limit)*100
|
||||||
|
if pcnt != last_pcnt:
|
||||||
let text = getDesign(pcnt)
|
let text = getDesign(pcnt)
|
||||||
let data = i3barData(
|
let data = i3barData(
|
||||||
full_text: text,
|
full_text: text,
|
||||||
|
@ -40,13 +44,29 @@ proc getBrightness() =
|
||||||
border: yellow
|
border: yellow
|
||||||
)
|
)
|
||||||
outputJSON(data)
|
outputJSON(data)
|
||||||
|
if run_once:
|
||||||
|
break
|
||||||
|
last_pcnt = pcnt
|
||||||
|
sleep(1000)
|
||||||
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
case input.button:
|
||||||
|
of 1,4:
|
||||||
|
let state = execCmd("xbacklight -inc 5")
|
||||||
|
get_brightness(true)
|
||||||
|
of 3,5:
|
||||||
|
let state = execCmd("xbacklight -dec 5")
|
||||||
|
get_brightness(true)
|
||||||
|
else:
|
||||||
|
let no = false
|
||||||
|
|
||||||
|
clearInput(2)
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
if len(args) > 0:
|
spawn get_brightness()
|
||||||
if args[0] == "4":
|
spawn await_click_info()
|
||||||
discard execCmd("xbacklight -inc 5")
|
sync()
|
||||||
elif args[0] == "5":
|
|
||||||
discard execCmd("xbacklight -dec 5")
|
|
||||||
getBrightness()
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import std/os
|
||||||
import std/times
|
import std/times
|
||||||
import std/osproc
|
import std/osproc
|
||||||
import std/re
|
import std/re
|
||||||
|
import std/threadpool
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
|
|
||||||
let args = getArguments()
|
let args = getArguments()
|
||||||
|
@ -14,7 +15,8 @@ proc getObject(date: string): i3barData =
|
||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
proc openCalendar(datestr: string) =
|
#proc openCalendar(datestr: string) =
|
||||||
|
proc openCalendar() =
|
||||||
var c = """yad --calendar \
|
var c = """yad --calendar \
|
||||||
--undecorated --fixed --close-on-unfocus --no-buttons \
|
--undecorated --fixed --close-on-unfocus --no-buttons \
|
||||||
--width="222" --height="193" \
|
--width="222" --height="193" \
|
||||||
|
@ -26,18 +28,23 @@ proc openCalendar(datestr: string) =
|
||||||
discard execCmd(c)
|
discard execCmd(c)
|
||||||
|
|
||||||
proc getDate() =
|
proc getDate() =
|
||||||
|
while true:
|
||||||
let now = now()
|
let now = now()
|
||||||
let d = now.format("yyyy-MM-dd")
|
let d = now.format("yyyy-MM-dd")
|
||||||
let data = getObject(d)
|
let data = getObject(d)
|
||||||
outputJSON(data)
|
outputJSON(data)
|
||||||
if len(args) > 0 and args[0] == "1":
|
sleep(30000)
|
||||||
openCalendar(now.format("ddd dd HH:MM"))
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
if input.button == 1:
|
||||||
|
openCalendar()
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
getDate()
|
spawn getDate()
|
||||||
#while true:
|
spawn await_click_info()
|
||||||
# let input = parseInput()
|
sync()
|
||||||
# if input.button == 1:
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
40
i3bar_pingclock.nim
Normal file
40
i3bar_pingclock.nim
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import std/os
|
||||||
|
import std/osproc
|
||||||
|
import std/re
|
||||||
|
import strutils
|
||||||
|
import i3bar_base
|
||||||
|
|
||||||
|
const host: string = "8.8.8.8"
|
||||||
|
const cmd: string = "ping -c 1 " & host
|
||||||
|
const time_secs: int = 4
|
||||||
|
|
||||||
|
let ping_re = re(r"time=[0-9.]+\sms")
|
||||||
|
|
||||||
|
proc get_pingms(): string =
|
||||||
|
let cmdOut = execCmdEx(cmd)
|
||||||
|
let lines = splitLines(cmdOut.output)
|
||||||
|
let ping_line = lines[1]
|
||||||
|
let bounds = findBounds(ping_line, ping_re)
|
||||||
|
if bounds.first > 0:
|
||||||
|
let ping = ping_line[bounds.first+5..bounds.last]
|
||||||
|
return "🏓 " & ping
|
||||||
|
return "❌ No Pong"
|
||||||
|
|
||||||
|
proc getObject(ping: string): i3barData =
|
||||||
|
let data = i3barData(
|
||||||
|
full_text: ping,
|
||||||
|
color: foreground,
|
||||||
|
border: lightblue,
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
while true:
|
||||||
|
let ping = get_pingms()
|
||||||
|
let data = getObject(ping)
|
||||||
|
outputJSON(data)
|
||||||
|
|
||||||
|
sleep(time_secs * 1000)
|
||||||
|
|
||||||
|
main()
|
60
i3bar_wlan.nim
Executable file
60
i3bar_wlan.nim
Executable file
|
@ -0,0 +1,60 @@
|
||||||
|
import i3bar_base
|
||||||
|
import std/os
|
||||||
|
import std/osproc
|
||||||
|
import std/threadpool
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
const wlan_nic: string ="wlp2s0"
|
||||||
|
|
||||||
|
# /sys/class/net/wlp2s0/operstate up or down if connected
|
||||||
|
|
||||||
|
proc get_essid(): string =
|
||||||
|
let essid = execCmdEx("iwgetid -r")
|
||||||
|
return strip(essid.output)
|
||||||
|
|
||||||
|
proc get_signal_quality(): string =
|
||||||
|
let wl = readFile("/proc/net/wireless")
|
||||||
|
let ln = splitLines(wl)[2]
|
||||||
|
let links = split(ln," ")
|
||||||
|
var qual = strip(links[1])
|
||||||
|
qual = replace(qual,".","")
|
||||||
|
return "[" & qual & "]"
|
||||||
|
|
||||||
|
proc get_wifi(): (string, string) =
|
||||||
|
let essid = get_essid()
|
||||||
|
if essid == "":
|
||||||
|
return ("disconnected", "")
|
||||||
|
let quality = get_signal_quality()
|
||||||
|
return (essid, quality)
|
||||||
|
|
||||||
|
proc getObject(conn: string): i3barData =
|
||||||
|
let data = i3barData(
|
||||||
|
full_text: conn,
|
||||||
|
color: foreground,
|
||||||
|
border: purple,
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
|
proc get_wifi_info() =
|
||||||
|
var last_qual = ""
|
||||||
|
while true:
|
||||||
|
let (essid, quality) = get_wifi()
|
||||||
|
if quality != last_qual:
|
||||||
|
let data = getObject(quality & " " & essid)
|
||||||
|
outputJSON(data)
|
||||||
|
last_qual = quality
|
||||||
|
sleep(1000)
|
||||||
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
if input.button == 1:
|
||||||
|
discard execCmd("alacritty -e nmtui-connect")
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
if dirExists("/sys/class/net/" & wlan_nic):
|
||||||
|
spawn get_wifi_info()
|
||||||
|
spawn await_click_info()
|
||||||
|
sync()
|
||||||
|
|
||||||
|
main()
|
Loading…
Reference in a new issue