loads of changes - will now give options in dmenu entries to change configs etc, volume, brights....
This commit is contained in:
parent
31f2b20d03
commit
89b73b613c
17 changed files with 318 additions and 142 deletions
|
@ -1,4 +1,4 @@
|
||||||
import std/[os,osproc]
|
import std/[os,osproc,strutils]
|
||||||
import std/json
|
import std/json
|
||||||
import std/rdstdin
|
import std/rdstdin
|
||||||
import marshal
|
import marshal
|
||||||
|
@ -7,6 +7,7 @@ type
|
||||||
i3BarData* = object
|
i3BarData* = object
|
||||||
title*: string
|
title*: string
|
||||||
full_text*: string
|
full_text*: string
|
||||||
|
html_text*: string
|
||||||
short_text*: string
|
short_text*: string
|
||||||
color*: string
|
color*: string
|
||||||
border*: string
|
border*: string
|
||||||
|
@ -41,7 +42,8 @@ const secondary* = red
|
||||||
const alert* = "#bd2c40"
|
const alert* = "#bd2c40"
|
||||||
var loop* = true
|
var loop* = true
|
||||||
var stoploop* = false
|
var stoploop* = false
|
||||||
var dmenu* = false
|
var dmenu = false
|
||||||
|
var rofi = false
|
||||||
|
|
||||||
proc newi3BarData*(): i3BarData =
|
proc newi3BarData*(): i3BarData =
|
||||||
return i3BarData(
|
return i3BarData(
|
||||||
|
@ -74,20 +76,43 @@ proc getArguments*(): seq[string] =
|
||||||
let args = commandLineParams()
|
let args = commandLineParams()
|
||||||
return args
|
return args
|
||||||
|
|
||||||
proc outputJSON*(data: i3barData) =
|
proc runDMenu*(data: i3BarData, opts: varargs[string]): string =
|
||||||
echo $$data
|
var cmd = "echo -e \"" & $data.full_text & "\n"
|
||||||
|
for opt in opts:
|
||||||
proc runDMenu*(data: i3BarData) =
|
cmd = cmd & opt & "\n"
|
||||||
var cmd = "echo " & $data.full_text & " | dmenu "
|
cmd = cmd & "\" | dmenu"
|
||||||
#cmd = cmd & " -l 2 "
|
#cmd = cmd & " -l 2 "
|
||||||
cmd = cmd & " -p \"" & $data.title & "\""
|
cmd = cmd & " -p \"" & $data.title & "\""
|
||||||
cmd = cmd & " -nb \"" & $data.background & "\""
|
cmd = cmd & " -nb \"" & $data.background & "\""
|
||||||
cmd = cmd & " -nf \"" & $data.color & "\""
|
cmd = cmd & " -nf \"" & $data.color & "\""
|
||||||
cmd = cmd & " -sb \"" & $data.border & "\""
|
cmd = cmd & " -sb \"" & $data.border & "\""
|
||||||
cmd = cmd & " -sf \"" & $data.color & "\""
|
cmd = cmd & " -sf \"" & $data.color & "\""
|
||||||
|
#echo "Dmenu :", cmd
|
||||||
|
let output = execCmdEx(cmd)
|
||||||
|
let option:string = strip(output[0])
|
||||||
|
discard execCmd("i3-msg mode \"default\"")
|
||||||
|
return option
|
||||||
|
|
||||||
|
proc runRofi*(data: i3BarData) =
|
||||||
|
var cmd = "rofi"
|
||||||
|
cmd = cmd & " -e \"" & $data.full_text & "\""
|
||||||
|
#echo "Rofi : ", cmd
|
||||||
discard execCmd(cmd)
|
discard execCmd(cmd)
|
||||||
discard execCmd("i3-msg mode \"default\"")
|
discard execCmd("i3-msg mode \"default\"")
|
||||||
|
|
||||||
|
proc outputJSON*(data: i3barData, args: seq[string]): string {.discardable.} =
|
||||||
|
var output = ""
|
||||||
|
if dmenu:
|
||||||
|
output = runDMenu(data, args)
|
||||||
|
elif rofi:
|
||||||
|
runRofi(data)
|
||||||
|
else:
|
||||||
|
var j_data = data
|
||||||
|
if j_data.html_text != "":
|
||||||
|
j_data.full_text = j_data.html_text
|
||||||
|
echo $$j_data
|
||||||
|
return output
|
||||||
|
|
||||||
let args = getArguments()
|
let args = getArguments()
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if arg == "noloop":
|
if arg == "noloop":
|
||||||
|
@ -95,5 +120,8 @@ for arg in args:
|
||||||
if arg == "dmenu":
|
if arg == "dmenu":
|
||||||
stoploop = true
|
stoploop = true
|
||||||
dmenu = true
|
dmenu = true
|
||||||
|
if arg == "rofi":
|
||||||
|
stoploop = true
|
||||||
|
rofi = true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ proc get_charge(): int =
|
||||||
charge = parseInt(chg)
|
charge = parseInt(chg)
|
||||||
return charge
|
return charge
|
||||||
|
|
||||||
proc get_design(charge: int, state: bool): (string, string, string, string) =
|
proc get_design(charge: int, state: bool): (string, string, string, string, string) =
|
||||||
var icon = " "
|
var icon = " "
|
||||||
var icon_colour = lightgreen
|
var icon_colour = lightgreen
|
||||||
var col = foreground
|
var col = foreground
|
||||||
|
@ -60,13 +60,16 @@ proc get_design(charge: int, state: bool): (string, string, string, string) =
|
||||||
else:
|
else:
|
||||||
icon = "x "
|
icon = "x "
|
||||||
|
|
||||||
|
let main_text = icon & " " & $charge & "%"
|
||||||
let text = "<span foreground=\"" & icon_colour & "\">" & icon & "</span>" & $charge & "%"
|
let text = "<span foreground=\"" & icon_colour & "\">" & icon & "</span>" & $charge & "%"
|
||||||
return (text, col, bg, border)
|
return (text,main_text, col, bg, border)
|
||||||
|
|
||||||
proc get_output(charge: int, state: bool): i3barData =
|
proc get_output(charge: int, state: bool): i3barData =
|
||||||
let (text,col,bg_col,bord_col) = get_design(charge, state)
|
let (text,main_text,col,bg_col,bord_col) = get_design(charge, state)
|
||||||
let data = i3barData(
|
let data = i3barData(
|
||||||
full_text: text,
|
title: "Battery : ",
|
||||||
|
full_text: main_text,
|
||||||
|
html_text: text,
|
||||||
color: col,
|
color: col,
|
||||||
border: bord_col,
|
border: bord_col,
|
||||||
background: bg_col
|
background: bg_col
|
||||||
|
@ -85,6 +88,8 @@ proc get_battery_info() =
|
||||||
outputJSON(data)
|
outputJSON(data)
|
||||||
last_charge = charge
|
last_charge = charge
|
||||||
last_state = state
|
last_state = state
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
|
|
|
@ -3,7 +3,6 @@ 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
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ proc getDesign(pcnt: float): string =
|
||||||
let text = icon & " " & $percent & "%"
|
let text = icon & " " & $percent & "%"
|
||||||
return text
|
return text
|
||||||
|
|
||||||
proc get_brightness(run_once: bool = false) =
|
proc get_brightness*(run_once: bool = false) =
|
||||||
var last_pcnt: float = 0
|
var last_pcnt: float = 0
|
||||||
while true:
|
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")))
|
||||||
|
@ -39,32 +38,28 @@ proc get_brightness(run_once: bool = false) =
|
||||||
if pcnt != last_pcnt:
|
if pcnt != last_pcnt:
|
||||||
let text = getDesign(pcnt)
|
let text = getDesign(pcnt)
|
||||||
var data = newi3BarData()
|
var data = newi3BarData()
|
||||||
|
data.title = "Brightness : "
|
||||||
data.full_text = text
|
data.full_text = text
|
||||||
data.border = yellow
|
data.border = yellow
|
||||||
outputJSON(data)
|
let args = @["up", "down"]
|
||||||
|
let option = outputJSON(data,args)
|
||||||
|
case option:
|
||||||
|
of "up":
|
||||||
|
discard execCmd("xbacklight -inc 5")
|
||||||
|
get_brightness(true)
|
||||||
|
of "down":
|
||||||
|
discard execCmd("xbacklight -dec 5")
|
||||||
|
get_brightness(true)
|
||||||
|
|
||||||
if run_once:
|
if run_once:
|
||||||
break
|
break
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
last_pcnt = pcnt
|
last_pcnt = pcnt
|
||||||
sleep(1000)
|
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() =
|
||||||
spawn get_brightness()
|
get_brightness()
|
||||||
spawn await_click_info()
|
|
||||||
sync()
|
|
||||||
|
|
||||||
main()
|
if isMainModule:
|
||||||
|
main()
|
||||||
|
|
27
i3bar_brightness_threads.nim
Normal file
27
i3bar_brightness_threads.nim
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import i3bar_base
|
||||||
|
import i3bar_brightness
|
||||||
|
import std/threadpool
|
||||||
|
import std/osproc
|
||||||
|
|
||||||
|
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() =
|
||||||
|
spawn get_brightness()
|
||||||
|
spawn await_click_info()
|
||||||
|
sync()
|
||||||
|
|
||||||
|
if isMainModule:
|
||||||
|
main()
|
|
@ -2,56 +2,65 @@ 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()
|
||||||
|
|
||||||
proc getObject(date: string): i3barData =
|
proc getObject(date: string): i3barData =
|
||||||
let data = i3barData(
|
var data = newi3barData()
|
||||||
full_text: date,
|
data.title = "Date : "
|
||||||
color: foreground,
|
data.full_text = date
|
||||||
border: blue
|
data.border = blue
|
||||||
)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
#proc openCalendar(datestr: string) =
|
#proc openCalendar(datestr: string) =
|
||||||
proc openCalendar(input: i3barInput) =
|
proc newCalendar(): string =
|
||||||
|
|
||||||
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" \
|
||||||
--posx="%pos_x" --posy="%pos_y" \
|
--posx="%pos_x" --posy="%pos_y" \
|
||||||
--title="yad-calendar" --borders 0 > /dev/null
|
--title="yad-calendar" --borders 0 > /dev/null
|
||||||
"""
|
"""
|
||||||
|
return c
|
||||||
|
proc openCalendar*(input: i3barInput) =
|
||||||
|
var c = newCalendar()
|
||||||
|
|
||||||
c = replace(c,re"%pos_x", $(input.x - 111))
|
c = replace(c,re"%pos_x", $(input.x - 111))
|
||||||
c = replace(c,re"%pos_y", $input.y)
|
c = replace(c,re"%pos_y", $input.y)
|
||||||
|
|
||||||
discard execCmd(c)
|
discard execCmd(c)
|
||||||
|
|
||||||
proc getDate() =
|
proc dmenuCalendar() =
|
||||||
|
var c = newCalendar()
|
||||||
|
|
||||||
|
c = replace(c,re"%pos_x", "100")
|
||||||
|
c = replace(c,re"%pos_y", "0")
|
||||||
|
|
||||||
|
discard execCmd(c)
|
||||||
|
|
||||||
|
|
||||||
|
proc getDate*() =
|
||||||
var last_date = ""
|
var last_date = ""
|
||||||
while true:
|
while true:
|
||||||
let now = now()
|
let now = now()
|
||||||
let d = now.format("yyyy-MM-dd")
|
let d = now.format("yyyy-MM-dd")
|
||||||
if d != last_date:
|
if d != last_date:
|
||||||
let data = getObject(d)
|
let data = getObject(d)
|
||||||
outputJSON(data)
|
let args = @["open calendar"]
|
||||||
|
case outputJSON(data, args):
|
||||||
|
of "open calendar":
|
||||||
|
dmenuCalendar()
|
||||||
last_date = d
|
last_date = d
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
sleep(5000)
|
sleep(5000)
|
||||||
|
|
||||||
proc await_click_info() =
|
|
||||||
while true:
|
|
||||||
let input = parseInput()
|
|
||||||
if input.button == 1:
|
|
||||||
openCalendar(input)
|
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
spawn getDate()
|
getDate()
|
||||||
spawn await_click_info()
|
|
||||||
sync()
|
|
||||||
|
|
||||||
main()
|
if isMainModule:
|
||||||
|
main()
|
||||||
|
|
||||||
#DATE="$(date +"%a %d %H:%M")"
|
#DATE="$(date +"%a %d %H:%M")"
|
||||||
#if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
|
#if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
|
||||||
|
|
18
i3bar_date_threads.nim
Normal file
18
i3bar_date_threads.nim
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import std/threadpool
|
||||||
|
import i3bar_date
|
||||||
|
import i3bar_base
|
||||||
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
if input.button == 1:
|
||||||
|
openCalendar(input)
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
spawn getDate()
|
||||||
|
spawn await_click_info()
|
||||||
|
sync()
|
||||||
|
|
||||||
|
|
||||||
|
if isMainModule:
|
||||||
|
main()
|
|
@ -74,7 +74,7 @@ proc getObject(time: string): i3barData =
|
||||||
var data = newi3barData()
|
var data = newi3barData()
|
||||||
data.title = "Fuzzy Time :"
|
data.title = "Fuzzy Time :"
|
||||||
data.full_text = time
|
data.full_text = time
|
||||||
#data.color = foreground
|
data.color = foreground
|
||||||
data.border = lightblue
|
data.border = lightblue
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -85,12 +85,12 @@ proc main() =
|
||||||
let time = get_fuzzytime()
|
let time = get_fuzzytime()
|
||||||
if time != last_time:
|
if time != last_time:
|
||||||
let data = getObject(time)
|
let data = getObject(time)
|
||||||
if dmenu:
|
|
||||||
runDMenu(data)
|
|
||||||
break
|
|
||||||
outputJSON(data)
|
outputJSON(data)
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
last_time = time
|
last_time = time
|
||||||
|
|
||||||
sleep(2000)
|
sleep(2000)
|
||||||
|
|
||||||
main()
|
if isMainModule:
|
||||||
|
main()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
import std/os
|
import std/os
|
||||||
import std/osproc
|
import std/osproc
|
||||||
import std/threadpool
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
const nics: seq[string] = @["wlan0", "enp3s0","wlp2s0","enp0s20f0u3"]
|
const nics: seq[string] = @["wlan0", "enp3s0","wlp2s0","enp0s20f0u3"]
|
||||||
|
@ -25,29 +24,31 @@ proc get_net(nic: string): (string, string) =
|
||||||
|
|
||||||
proc getObject(conn: string, nic: string): i3barData =
|
proc getObject(conn: string, nic: string): i3barData =
|
||||||
var data = newi3barData()
|
var data = newi3barData()
|
||||||
|
data.title = "IP :"
|
||||||
data.full_text = conn
|
data.full_text = conn
|
||||||
data.border = purple
|
data.border = purple
|
||||||
return data
|
return data
|
||||||
|
|
||||||
proc get_net_info(nic: string) =
|
proc get_net_info*(nic: string) =
|
||||||
var last_ip = ""
|
var last_ip = ""
|
||||||
var last_state = ""
|
var last_state = ""
|
||||||
while true:
|
while true:
|
||||||
let (ip, state) = get_net(nic)
|
let (ip, state) = get_net(nic)
|
||||||
if ip != last_ip or state != last_state:
|
if ip != last_ip or state != last_state:
|
||||||
let data = getObject(state & " " & ip, nic)
|
let data = getObject(state & " " & ip, nic)
|
||||||
outputJSON(data)
|
let args = @["nmtui-connect"]
|
||||||
|
let option = outputJSON(data, args)
|
||||||
|
case option:
|
||||||
|
of "nmtui-connect":
|
||||||
|
discard execCmd("alacritty -e nmtui-connect")
|
||||||
last_ip = ip
|
last_ip = ip
|
||||||
last_state = state
|
last_state = state
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
|
|
||||||
proc await_click_info() =
|
|
||||||
while true:
|
|
||||||
let input = parseInput()
|
|
||||||
if input.button == 1:
|
|
||||||
discard execCmd("alacritty -e nmtui-connect")
|
|
||||||
|
|
||||||
proc get_nic(): string =
|
proc get_nic*(): string =
|
||||||
for nic in nics:
|
for nic in nics:
|
||||||
if dirExists("/sys/class/net/" & nic):
|
if dirExists("/sys/class/net/" & nic):
|
||||||
return nic
|
return nic
|
||||||
|
@ -56,9 +57,7 @@ proc get_nic(): string =
|
||||||
proc main() =
|
proc main() =
|
||||||
let mynic = get_nic()
|
let mynic = get_nic()
|
||||||
if dirExists("/sys/class/net/" & mynic):
|
if dirExists("/sys/class/net/" & mynic):
|
||||||
spawn get_net_info(mynic)
|
get_net_info(mynic)
|
||||||
spawn await_click_info()
|
|
||||||
sync()
|
|
||||||
else:
|
else:
|
||||||
echo "No NIC"
|
echo "No NIC"
|
||||||
|
|
||||||
|
|
25
i3bar_nic_threads.nim
Normal file
25
i3bar_nic_threads.nim
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import i3bar_base
|
||||||
|
import i3bar_nic
|
||||||
|
import std/os
|
||||||
|
import std/osproc
|
||||||
|
import std/threadpool
|
||||||
|
import strutils
|
||||||
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
if input.button == 1:
|
||||||
|
discard execCmd("alacritty -e nmtui-connect")
|
||||||
|
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
let mynic = get_nic()
|
||||||
|
if dirExists("/sys/class/net/" & mynic):
|
||||||
|
spawn get_net_info(mynic)
|
||||||
|
spawn await_click_info()
|
||||||
|
sync()
|
||||||
|
else:
|
||||||
|
echo "No NIC"
|
||||||
|
|
||||||
|
if isMainModule:
|
||||||
|
main()
|
|
@ -68,14 +68,12 @@ proc main() =
|
||||||
let ping = get_ping()
|
let ping = get_ping()
|
||||||
if ping != last_ping:
|
if ping != last_ping:
|
||||||
let data = getObject(ping)
|
let data = getObject(ping)
|
||||||
if dmenu:
|
outputJSON(data)
|
||||||
runDMenu(data)
|
last_ping = ping
|
||||||
else:
|
|
||||||
outputJSON(data)
|
|
||||||
last_ping = ping
|
|
||||||
loop = not stoploop
|
loop = not stoploop
|
||||||
if loop:
|
if loop:
|
||||||
sleep(time_secs * 1000)
|
sleep(time_secs * 1000)
|
||||||
|
|
||||||
|
|
||||||
main()
|
if isMainModule:
|
||||||
|
main()
|
||||||
|
|
|
@ -41,11 +41,13 @@ proc getObject(temp: int): i3barData =
|
||||||
colour = green
|
colour = green
|
||||||
icon = ""
|
icon = ""
|
||||||
let text = "<span foreground='" & colour & "'>" & icon & "</span> " & $temp & "°C"
|
let text = "<span foreground='" & colour & "'>" & icon & "</span> " & $temp & "°C"
|
||||||
let data = i3barData(
|
let main_text = icon & " " & $temp & "°C"
|
||||||
full_text: text,
|
var data = newi3barData()
|
||||||
color: foreground,
|
data.title = "Temp : "
|
||||||
border: colour
|
data.full_text = main_text
|
||||||
)
|
data.html_text = text
|
||||||
|
data.color = foreground
|
||||||
|
data.border = colour
|
||||||
return data
|
return data
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
|
@ -57,6 +59,8 @@ proc main() =
|
||||||
let data = getObject(temp)
|
let data = getObject(temp)
|
||||||
outputJSON(data)
|
outputJSON(data)
|
||||||
last_temp = temp
|
last_temp = temp
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
sleep(10000)
|
sleep(10000)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -3,13 +3,11 @@ import i3bar_base
|
||||||
import std/re
|
import std/re
|
||||||
import std/httpclient
|
import std/httpclient
|
||||||
import std/os
|
import std/os
|
||||||
import std/json
|
|
||||||
import std/times
|
import std/times
|
||||||
import std/threadpool
|
|
||||||
import std/osproc
|
import std/osproc
|
||||||
|
|
||||||
const url = "https://www.tidetimes.org.uk/%LOC-tide-times"
|
const url* = "https://www.tidetimes.org.uk/%LOC-tide-times"
|
||||||
const loc = "exmouth-dock"
|
const loc* = "exmouth-dock"
|
||||||
const icon: string = "🌊"
|
const icon: string = "🌊"
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -86,9 +84,7 @@ proc getDesign(tides: seq[Tide]): i3barData =
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
proc getTides*() {.gcsafe.}=
|
||||||
|
|
||||||
proc getTides() {.gcsafe.}=
|
|
||||||
var mytides = TideList()
|
var mytides = TideList()
|
||||||
var last_data = ""
|
var last_data = ""
|
||||||
while true:
|
while true:
|
||||||
|
@ -99,20 +95,11 @@ proc getTides() {.gcsafe.}=
|
||||||
if $data != last_data:
|
if $data != last_data:
|
||||||
outputJSON(data)
|
outputJSON(data)
|
||||||
last_data = $data
|
last_data = $data
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
sleep(10000)
|
sleep(10000)
|
||||||
|
|
||||||
proc await_click_info() =
|
|
||||||
while true:
|
|
||||||
let input = parseInput()
|
|
||||||
case input.button:
|
|
||||||
of 1:
|
|
||||||
let state = execCmd("xdg-open " & replace(url,re"\%LOC",loc))
|
|
||||||
else:
|
|
||||||
let no = false
|
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
spawn getTides()
|
getTides()
|
||||||
spawn await_click_info()
|
|
||||||
sync()
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
21
i3bar_tides_threads.nim
Normal file
21
i3bar_tides_threads.nim
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import i3bar_tides
|
||||||
|
import i3bar_base
|
||||||
|
import std/re
|
||||||
|
import std/threadpool
|
||||||
|
import std/osproc
|
||||||
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
case input.button:
|
||||||
|
of 1:
|
||||||
|
let state = execCmd("xdg-open " & replace(url,re"\%LOC",loc))
|
||||||
|
else:
|
||||||
|
let no = false
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
spawn getTides()
|
||||||
|
spawn await_click_info()
|
||||||
|
sync()
|
||||||
|
|
||||||
|
main()
|
|
@ -3,7 +3,6 @@ import strutils
|
||||||
import std/osproc
|
import std/osproc
|
||||||
import std/math
|
import std/math
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
import std/threadpool
|
|
||||||
|
|
||||||
proc get_current_volume(): string {.gcsafe.}
|
proc get_current_volume(): string {.gcsafe.}
|
||||||
|
|
||||||
|
@ -15,11 +14,11 @@ proc check_volume(volume: string): string =
|
||||||
vol = check_volume(vol)
|
vol = check_volume(vol)
|
||||||
return vol
|
return vol
|
||||||
|
|
||||||
proc getDesign(volume: string): string =
|
proc getDesign(volume: string): (string,string) =
|
||||||
let vol = check_volume(volume)
|
let vol = check_volume(volume)
|
||||||
var icon = " "
|
var icon = " "
|
||||||
if vol == "muted":
|
if vol == "muted":
|
||||||
return icon & "muted"
|
return (icon & "muted", "")
|
||||||
let pcnt = parseInt(strip(vol))
|
let pcnt = parseInt(strip(vol))
|
||||||
case pcnt:
|
case pcnt:
|
||||||
of 85..100:
|
of 85..100:
|
||||||
|
@ -32,8 +31,9 @@ proc getDesign(volume: string): string =
|
||||||
icon = " "
|
icon = " "
|
||||||
else:
|
else:
|
||||||
icon = " "
|
icon = " "
|
||||||
|
let main_text = icon & $pcnt & "%"
|
||||||
let text = "<span size=\"x-large\">" & icon & "</span>" & $pcnt & "%"
|
let text = "<span size=\"x-large\">" & icon & "</span>" & $pcnt & "%"
|
||||||
return text
|
return (text, main_text)
|
||||||
|
|
||||||
proc get_current_volume(): string =
|
proc get_current_volume(): string =
|
||||||
let mute = execCmdEx("pamixer --get-mute")
|
let mute = execCmdEx("pamixer --get-mute")
|
||||||
|
@ -42,49 +42,47 @@ proc get_current_volume(): string =
|
||||||
let vol = execCmdEx("pamixer --get-volume")
|
let vol = execCmdEx("pamixer --get-volume")
|
||||||
return vol.output
|
return vol.output
|
||||||
|
|
||||||
proc get_volume(run_once: bool = false) =
|
proc get_volume*(run_once: bool = false) =
|
||||||
var last_vol: string = ""
|
var last_vol: string = ""
|
||||||
while true:
|
while true:
|
||||||
let vol = get_current_volume()
|
let vol = get_current_volume()
|
||||||
if vol != last_vol or true:
|
if vol != last_vol or true:
|
||||||
let text = getDesign(vol)
|
let (text, main_text) = getDesign(vol)
|
||||||
let data = i3barData(
|
let data = i3barData(
|
||||||
full_text: text,
|
title: "Volume : ",
|
||||||
|
html_text: text,
|
||||||
|
full_text: main_text,
|
||||||
color: foreground,
|
color: foreground,
|
||||||
border: green,
|
border: green,
|
||||||
background: black
|
background: black
|
||||||
)
|
)
|
||||||
outputJSON(data)
|
let args = @["up", "down", "mute", "ncpamixer", "pavucontrol"]
|
||||||
|
let option = outputJSON(data,args)
|
||||||
|
case option:
|
||||||
|
of "up":
|
||||||
|
discard execCmd("pamixer -i 5")
|
||||||
|
get_volume()
|
||||||
|
of "down":
|
||||||
|
discard execCmd("pamixer -d 5")
|
||||||
|
get_volume()
|
||||||
|
of "mute":
|
||||||
|
discard execCmd("pamixer -t")
|
||||||
|
get_volume()
|
||||||
|
of "ncpamixer":
|
||||||
|
discard execCmd("ncpamixer")
|
||||||
|
of "pavucontrol":
|
||||||
|
discard execCmd("pavucontrol")
|
||||||
|
|
||||||
|
|
||||||
if run_once:
|
if run_once:
|
||||||
break
|
break
|
||||||
last_vol = vol
|
last_vol = vol
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
|
if stoploop:
|
||||||
proc await_click_info() =
|
break
|
||||||
while true:
|
|
||||||
let input = parseInput()
|
|
||||||
case input.button:
|
|
||||||
of 4:
|
|
||||||
discard execCmd("pamixer -i 5")
|
|
||||||
get_volume(true)
|
|
||||||
clearInput(2)
|
|
||||||
of 5:
|
|
||||||
discard execCmd("pamixer -d 5")
|
|
||||||
get_volume(true)
|
|
||||||
clearInput(2)
|
|
||||||
of 1:
|
|
||||||
discard execCmd("pamixer -t")
|
|
||||||
get_volume(true)
|
|
||||||
of 3:
|
|
||||||
discard execCmd("alacritty -e ncpamixer")
|
|
||||||
get_volume(true)
|
|
||||||
else:
|
|
||||||
let no = false
|
|
||||||
|
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
spawn get_volume()
|
get_volume()
|
||||||
spawn await_click_info()
|
|
||||||
sync()
|
|
||||||
|
|
||||||
main()
|
if isMainModule:
|
||||||
|
main()
|
||||||
|
|
34
i3bar_volume_threads.nim
Normal file
34
i3bar_volume_threads.nim
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import i3bar_base
|
||||||
|
import i3bar_volume
|
||||||
|
import std/threadpool
|
||||||
|
import std/osproc
|
||||||
|
|
||||||
|
proc await_click_info() =
|
||||||
|
while true:
|
||||||
|
let input = parseInput()
|
||||||
|
case input.button:
|
||||||
|
of 4:
|
||||||
|
discard execCmd("pamixer -i 5")
|
||||||
|
get_volume(true)
|
||||||
|
clearInput(2)
|
||||||
|
of 5:
|
||||||
|
discard execCmd("pamixer -d 5")
|
||||||
|
get_volume(true)
|
||||||
|
clearInput(2)
|
||||||
|
of 1:
|
||||||
|
discard execCmd("pamixer -t")
|
||||||
|
get_volume(true)
|
||||||
|
of 3:
|
||||||
|
discard execCmd("alacritty -e ncpamixer")
|
||||||
|
get_volume(true)
|
||||||
|
else:
|
||||||
|
let no = false
|
||||||
|
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
spawn get_volume()
|
||||||
|
spawn await_click_info()
|
||||||
|
sync()
|
||||||
|
|
||||||
|
if isMainModule:
|
||||||
|
main()
|
|
@ -1,10 +1,9 @@
|
||||||
import i3bar_base
|
import i3bar_base
|
||||||
import std/os
|
import std/os
|
||||||
import std/osproc
|
import std/osproc
|
||||||
import std/threadpool
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
const wlan_nic: string ="wlan0"
|
const wlan_nic*: string ="wlan0"
|
||||||
|
|
||||||
# /sys/class/net/wlp2s0/operstate up or down if connected
|
# /sys/class/net/wlp2s0/operstate up or down if connected
|
||||||
|
|
||||||
|
@ -29,18 +28,26 @@ proc get_wifi(): (string, string) =
|
||||||
|
|
||||||
proc getObject(conn: string): i3barData =
|
proc getObject(conn: string): i3barData =
|
||||||
var data = newi3barData()
|
var data = newi3barData()
|
||||||
|
data.title = "WiFi : "
|
||||||
data.full_text = conn
|
data.full_text = conn
|
||||||
data.border = purple
|
data.border = purple
|
||||||
return data
|
return data
|
||||||
|
|
||||||
proc get_wifi_info() =
|
proc get_wifi_info*() =
|
||||||
var last_qual = ""
|
var last_qual = ""
|
||||||
while true:
|
while true:
|
||||||
let (essid, quality) = get_wifi()
|
let (essid, quality) = get_wifi()
|
||||||
if quality != last_qual:
|
if quality != last_qual:
|
||||||
let data = getObject(quality & " " & essid)
|
let data = getObject(quality & " " & essid)
|
||||||
outputJSON(data)
|
let args = @["nmtui-connect"]
|
||||||
|
let output = outputJSON(data, args)
|
||||||
|
echo output
|
||||||
|
case output:
|
||||||
|
of "nmtui-connect":
|
||||||
|
discard execCmd("alacritty -e nmtui-connect")
|
||||||
last_qual = quality
|
last_qual = quality
|
||||||
|
if stoploop:
|
||||||
|
break
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
|
|
||||||
proc await_click_info() =
|
proc await_click_info() =
|
||||||
|
@ -51,10 +58,9 @@ proc await_click_info() =
|
||||||
|
|
||||||
proc main() =
|
proc main() =
|
||||||
if dirExists("/sys/class/net/" & wlan_nic):
|
if dirExists("/sys/class/net/" & wlan_nic):
|
||||||
spawn get_wifi_info()
|
get_wifi_info()
|
||||||
spawn await_click_info()
|
|
||||||
sync()
|
|
||||||
else:
|
else:
|
||||||
echo "No WLAN"
|
echo "No WLAN"
|
||||||
|
|
||||||
main()
|
if isMainModule:
|
||||||
|
main()
|
||||||
|
|
22
i3bar_wlan_threads.nim
Executable file
22
i3bar_wlan_threads.nim
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
import i3bar_base
|
||||||
|
import i3bar_wlan
|
||||||
|
import std/[os,osproc]
|
||||||
|
import std/threadpool
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
else:
|
||||||
|
echo "No WLAN"
|
||||||
|
|
||||||
|
if isMainModule:
|
||||||
|
main()
|
Loading…
Reference in a new issue