diff --git a/i3bar_base.nim b/i3bar_base.nim old mode 100755 new mode 100644 index d7e5a22..3badf41 --- a/i3bar_base.nim +++ b/i3bar_base.nim @@ -60,6 +60,7 @@ proc parseInput*(): i3BarInput = return i3input except: return i3BarInput() + proc clearInput*(count: int = 1) = for x in countup(1, count): discard readLineFromStdin("") diff --git a/i3bar_battery.nim b/i3bar_battery.nim index 3946bb0..a0ce348 100755 --- a/i3bar_battery.nim +++ b/i3bar_battery.nim @@ -75,7 +75,7 @@ proc get_output(charge: int, state: bool): i3barData = proc get_battery_info() = - var last_charge = 0 + var last_charge = -1 var last_state = false while true: let charge = get_charge() diff --git a/i3bar_brightness.nim b/i3bar_brightness.nim old mode 100755 new mode 100644 diff --git a/i3bar_date.nim b/i3bar_date.nim old mode 100755 new mode 100644 diff --git a/i3bar_fuzzytime.nim b/i3bar_fuzzytime.nim old mode 100755 new mode 100644 diff --git a/i3bar_nic.nim b/i3bar_nic.nim old mode 100755 new mode 100644 index 924fe09..f5c33f6 --- a/i3bar_nic.nim +++ b/i3bar_nic.nim @@ -6,8 +6,6 @@ import strutils const nics: seq[string] = @["wlan0", "enp3s0","wlp2s0","enp0s20f0u3"] -# /sys/class/net/*/operstate up or down if connected - proc get_ip(nic: string): string = let cmd = "ifconfig " & nic & " | grep inet | awk -F\" \" '{print $2}' | head -1 | awk '{print $1}'" let ip = execCmdEx(cmd) @@ -25,7 +23,7 @@ proc get_net(nic: string): (string, string) = return ("disconnected", state) return (ip, state) -proc getObject(conn: string): i3barData = +proc getObject(conn: string, nic: string): i3barData = var data = newi3barData() data.full_text = conn data.border = purple @@ -37,7 +35,7 @@ proc get_net_info(nic: string) = while true: let (ip, state) = get_net(nic) if ip != last_ip or state != last_state: - let data = getObject(state & " " & ip) + let data = getObject(state & " " & ip, nic) outputJSON(data) last_ip = ip last_state = state diff --git a/i3bar_pingclock.nim b/i3bar_pingclock.nim old mode 100755 new mode 100644 index 906e10b..2fe4d56 --- a/i3bar_pingclock.nim +++ b/i3bar_pingclock.nim @@ -49,16 +49,41 @@ proc getObject(ping: float): i3barData = ) return data +proc runDMenu(data: i3BarData) = + var cmd = "echo Ping Clock : " & $data.full_text & " | dmenu " + cmd = cmd & " -nb \"" & $data.background & "\"" + cmd = cmd & " -nf \"" & $data.color & "\"" + cmd = cmd & " -sb \"" & $data.background & "\"" + cmd = cmd & " -sf \"" & $data.color & "\"" + discard execCmd(cmd) + discard execCmd("i3-msg mode \"default\"") + proc main() = + let args = getArguments() + var loop = true + var stoploop = false + var dmenu = false + for arg in args: + if arg == "noloop": + stoploop = true + if arg == "dmenu": + stoploop = true + dmenu = true + var last_ping: float = 0 - while true: + while loop: let ping = get_ping() if ping != last_ping: let data = getObject(ping) outputJSON(data) last_ping = ping + if dmenu: + runDMenu(data) + + loop = not stoploop + if loop: + sleep(time_secs * 1000) - sleep(time_secs * 1000) main() diff --git a/i3bar_temperature.nim b/i3bar_temperature.nim old mode 100755 new mode 100644 diff --git a/i3bar_volume.nim b/i3bar_volume.nim old mode 100755 new mode 100644