diff --git a/i3bar_base.nim b/base.nim
similarity index 79%
rename from i3bar_base.nim
rename to base.nim
index 245f1d6..12bc120 100644
--- a/i3bar_base.nim
+++ b/base.nim
@@ -4,14 +4,16 @@ import std/rdstdin
import marshal
type
- i3BarData* = object
+ Info* = object
title*: string
full_text*: string
html_text*: string
short_text*: string
- color*: string
border*: string
+ color*: string
+ selected_color*: string
background*: string
+ selected_background*: string
type
i3BarInput* = object
@@ -45,13 +47,15 @@ var stoploop* = false
var dmenu = false
var rofi = false
-proc newi3BarData*(): i3BarData =
- return i3BarData(
+proc newInfo*(): Info =
+ return Info(
title: "Info : ",
full_text: "",
short_text: "",
color: foreground,
+ selected_color: background,
border: white,
+ selected_background: white,
background: black
)
proc debugLog*(str: string) =
@@ -76,31 +80,33 @@ proc getArguments*(): seq[string] =
let args = commandLineParams()
return args
-proc runDMenu*(data: i3BarData, opts: varargs[string]): string =
+proc runDMenu*(data: Info, opts: varargs[string]): string =
+ discard execCmd("i3-msg mode \"default\"")
var cmd = "echo -e \"" & $data.full_text & "\n"
for opt in opts:
cmd = cmd & opt & "\n"
+ cmd.removeSuffix("\n")
cmd = cmd & "\" | dmenu"
- #cmd = cmd & " -l 2 "
+ cmd = cmd & " -l " & $(len(opts) + 1)
cmd = cmd & " -p \"" & $data.title & "\""
- cmd = cmd & " -nb \"" & $data.background & "\""
- cmd = cmd & " -nf \"" & $data.color & "\""
- cmd = cmd & " -sb \"" & $data.border & "\""
- cmd = cmd & " -sf \"" & $data.color & "\""
+ cmd = cmd & " -nb \"" & $background & "\""
+ cmd = cmd & " -nf \"" & $foreground & "\""
+ cmd = cmd & " -sb \"" & $data.selected_background & "\""
+ cmd = cmd & " -sf \"" & $data.selected_color & "\""
+ cmd = cmd & " -fn Hermit-10"
#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) =
+proc runRofi*(data: Info) =
+ discard execCmd("i3-msg mode \"default\"")
var cmd = "rofi"
cmd = cmd & " -e \"" & $data.full_text & "\""
#echo "Rofi : ", cmd
discard execCmd(cmd)
- discard execCmd("i3-msg mode \"default\"")
-proc outputJSON*(data: i3barData, args: seq[string]): string {.discardable.} =
+proc outputJSON*(data: Info, args: varargs[string]): string {.discardable.} =
var output = ""
if dmenu:
output = runDMenu(data, args)
diff --git a/i3bar_battery.nim b/battery.nim
old mode 100755
new mode 100644
similarity index 92%
rename from i3bar_battery.nim
rename to battery.nim
index e693367..85f8f1d
--- a/i3bar_battery.nim
+++ b/battery.nim
@@ -1,6 +1,5 @@
-import i3bar_base
+import base
import strutils
-import std/times
import std/os
proc battery_exists(): bool =
@@ -64,15 +63,17 @@ proc get_design(charge: int, state: bool): (string, string, string, string, stri
let text = "" & icon & "" & $charge & "%"
return (text,main_text, col, bg, border)
-proc get_output(charge: int, state: bool): i3barData =
+proc get_output(charge: int, state: bool): Info =
let (text,main_text,col,bg_col,bord_col) = get_design(charge, state)
- let data = i3barData(
+ let data = Info(
title: "Battery : ",
full_text: main_text,
html_text: text,
color: col,
border: bord_col,
- background: bg_col
+ background: bg_col,
+ selected_background: bord_col,
+ selected_color: black
)
return data
diff --git a/i3bar_brightness.nim b/brightness.nim
similarity index 92%
rename from i3bar_brightness.nim
rename to brightness.nim
index dd6e60b..1691f63 100644
--- a/i3bar_brightness.nim
+++ b/brightness.nim
@@ -2,12 +2,11 @@ import std/os
import strutils
import std/osproc
import std/math
-import i3bar_base
+import base
proc getLimit(): int
let limit = getLimit()
-let args = getArguments()
proc getLimit(): int =
let limit = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/max_brightness")))
@@ -37,10 +36,12 @@ proc get_brightness*(run_once: bool = false) =
let pcnt = (current/limit)*100
if pcnt != last_pcnt:
let text = getDesign(pcnt)
- var data = newi3BarData()
+ var data = newInfo()
data.title = "Brightness : "
data.full_text = text
data.border = yellow
+ data.selected_background = yellow
+ data.selected_color = black
let args = @["up", "down"]
let option = outputJSON(data,args)
case option:
diff --git a/i3bar_date.nim b/date.nim
similarity index 93%
rename from i3bar_date.nim
rename to date.nim
index 5541a5e..138cfad 100644
--- a/i3bar_date.nim
+++ b/date.nim
@@ -2,15 +2,16 @@ import std/os
import std/times
import std/osproc
import std/re
-import i3bar_base
+import base
-let args = getArguments()
-proc getObject(date: string): i3barData =
- var data = newi3barData()
+proc getObject(date: string): Info =
+ var data = newInfo()
data.title = "Date : "
data.full_text = date
data.border = blue
+ data.selected_background = blue
+ data.selected_color = white
return data
#proc openCalendar(datestr: string) =
diff --git a/i3bar_fuzzytime.nim b/fuzzytime.nim
similarity index 92%
rename from i3bar_fuzzytime.nim
rename to fuzzytime.nim
index 8ca2b6d..d74b11b 100644
--- a/i3bar_fuzzytime.nim
+++ b/fuzzytime.nim
@@ -1,6 +1,6 @@
import std/times
import std/os
-import i3bar_base
+import base
proc get_hour(hr: int): string
proc get_minute(min: int): string
@@ -70,12 +70,14 @@ proc get_minute(min: int): string =
else:
return "error"
-proc getObject(time: string): i3barData =
- var data = newi3barData()
+proc getObject(time: string): Info =
+ var data = Info()
data.title = "Fuzzy Time :"
data.full_text = time
data.color = foreground
data.border = lightblue
+ data.selected_background = lightblue
+ data.selected_color = black
return data
diff --git a/i3bar_testblock.nim b/i3bar_testblock.nim
deleted file mode 100644
index 83f61cc..0000000
--- a/i3bar_testblock.nim
+++ /dev/null
@@ -1,45 +0,0 @@
-import std/os
-import strutils
-import std/osproc
-import std/math
-import i3bar_base
-import std/threadpool
-
-proc get_data() =
- while true:
- let data1 = i3barData(
- full_text: "Hello",
- color: foreground,
- border: yellow,
- background: black
- )
- outputJSON(data1)
- sleep(1000)
- let data2 = i3barData(
- full_text: "Bye",
- color: foreground,
- border: yellow,
- background: black
- )
- outputJSON(data2)
- sleep(1000)
-
-proc await_click_info() =
- while true:
- let input = parseInput()
- case input.button:
- of 1,4:
- get_data()
- of 3,5:
- get_data()
- else:
- let no = false
-
- clearInput(2)
-
-proc main() =
- spawn get_data()
- spawn await_click_info()
- sync()
-
-main()
diff --git a/i3bar_tides.nim b/i3bar_tides.nim
index 99412b5..1095d16 100644
--- a/i3bar_tides.nim
+++ b/i3bar_tides.nim
@@ -4,7 +4,6 @@ import std/re
import std/httpclient
import std/os
import std/times
-import std/osproc
const url* = "https://www.tidetimes.org.uk/%LOC-tide-times"
const loc* = "exmouth-dock"
@@ -43,6 +42,7 @@ proc getTideData(gettomorrow: bool = false): seq[Tide] =
link &= "-" & tomdate.format("yyyyMMdd")
try:
let data = client.getContent(link)
+ echo "Data : " & data
let times = findAll(data,fnd)
var tide: Tide
var count: int = 0
@@ -86,20 +86,22 @@ proc getDesign(tides: seq[Tide]): i3barData =
proc getTides*() {.gcsafe.}=
var mytides = TideList()
- var last_data = ""
+ var last_data = "-1"
while true:
if len(mytides.Tides) == 0 or mytides.LastUpdated < now() - initTimeInterval(hours = 1):
mytides.Tides = getTideData()
mytides.LastUpdated = now()
let data = getDesign(sortTides(mytides.Tides))
if $data != last_data:
- outputJSON(data)
+ let args: seq[string] = @[]
+ outputJSON(data,args)
last_data = $data
if stoploop:
break
sleep(10000)
proc main() =
- getTides()
+ getTides()
-main()
+if isMainModule:
+ main()
diff --git a/i3bar_brightness_threads.nim b/i3bar_tools/i3bar_brightness_threads.nim
similarity index 100%
rename from i3bar_brightness_threads.nim
rename to i3bar_tools/i3bar_brightness_threads.nim
diff --git a/i3bar_date_threads.nim b/i3bar_tools/i3bar_date_threads.nim
similarity index 100%
rename from i3bar_date_threads.nim
rename to i3bar_tools/i3bar_date_threads.nim
diff --git a/i3bar_nic_threads.nim b/i3bar_tools/i3bar_nic_threads.nim
similarity index 100%
rename from i3bar_nic_threads.nim
rename to i3bar_tools/i3bar_nic_threads.nim
diff --git a/i3bar_tides_threads.nim b/i3bar_tools/i3bar_tides_threads.nim
similarity index 100%
rename from i3bar_tides_threads.nim
rename to i3bar_tools/i3bar_tides_threads.nim
diff --git a/i3bar_volume_threads.nim b/i3bar_tools/i3bar_volume_threads.nim
similarity index 100%
rename from i3bar_volume_threads.nim
rename to i3bar_tools/i3bar_volume_threads.nim
diff --git a/i3bar_wlan_threads.nim b/i3bar_tools/i3bar_wlan_threads.nim
old mode 100755
new mode 100644
similarity index 100%
rename from i3bar_wlan_threads.nim
rename to i3bar_tools/i3bar_wlan_threads.nim
diff --git a/i3bar_nic.nim b/nic.nim
similarity index 90%
rename from i3bar_nic.nim
rename to nic.nim
index 36fdca1..9b074ac 100644
--- a/i3bar_nic.nim
+++ b/nic.nim
@@ -1,4 +1,4 @@
-import i3bar_base
+import base
import std/os
import std/osproc
import strutils
@@ -22,11 +22,13 @@ proc get_net(nic: string): (string, string) =
return ("disconnected", state)
return (ip, state)
-proc getObject(conn: string, nic: string): i3barData =
- var data = newi3barData()
+proc getObject(conn: string, nic: string): Info =
+ var data = newInfo()
data.title = "IP :"
data.full_text = conn
data.border = purple
+ data.selected_background = purple
+ data.selected_color = black
return data
proc get_net_info*(nic: string) =
diff --git a/i3bar_pingclock.nim b/pingclock.nim
similarity index 66%
rename from i3bar_pingclock.nim
rename to pingclock.nim
index 88c8942..41c755b 100644
--- a/i3bar_pingclock.nim
+++ b/pingclock.nim
@@ -2,8 +2,7 @@ import std/os
import std/osproc
import std/re
import strutils
-import i3bar_base
-import std/math
+import base
const host: string = "web.wilde.cloud"
const cmd: string = "ping -4 -c 1 " & host
@@ -22,7 +21,7 @@ proc get_ping(): float =
ping = parseFloat(png)
return ping
-proc getObject(ping: float): i3barData =
+proc getObject(ping: float): Info =
let pingstr = split($ping,".")
let niceping = pingstr[0] & "." & pingstr[1][0]
var text = "🏓 " & niceping & " ms"
@@ -41,26 +40,16 @@ proc getObject(ping: float): i3barData =
else:
col = red
- let data = i3barData(
- title: "Ping Clock:",
- full_text: text,
- color: col,
- border: blue,
- background: black
- )
+ var data = newInfo()
+ data.title = "Ping Clock:"
+ data.full_text = text
+ data.color = col
+ data.border = blue
+ data.background = black
+ data.selected_background = blue
+ data.selected_color = white
return data
-proc runDMenu(data: i3BarData) =
- var cmd = "echo " & $data.full_text & " | dmenu "
- #cmd = cmd & " -l 2 "
- cmd = cmd & " -p \"Ping Clock : \""
- cmd = cmd & " -nb \"" & $data.background & "\""
- cmd = cmd & " -nf \"" & $data.color & "\""
- cmd = cmd & " -sb \"" & $data.border & "\""
- cmd = cmd & " -sf \"" & $data.color & "\""
- discard execCmd(cmd)
- discard execCmd("i3-msg mode \"default\"")
-
proc main() =
var last_ping: float = 0
diff --git a/i3bar_temperature.nim b/temperature.nim
similarity index 91%
rename from i3bar_temperature.nim
rename to temperature.nim
index cfc0f4c..ee77fec 100644
--- a/i3bar_temperature.nim
+++ b/temperature.nim
@@ -2,7 +2,7 @@ import std/os
import std/re
import std/math
import strutils
-import i3bar_base
+import base
proc getThermalZones(): seq[string] =
@@ -27,7 +27,7 @@ proc getAverageTemp(zones: seq[string]): int =
let avgtemp = ceil((temps / len(zones))/1000)
return toInt(round(avgtemp,0))
-proc getObject(temp: int): i3barData =
+proc getObject(temp: int): Info =
var icon = ""
var colour = foreground
case temp:
@@ -42,12 +42,14 @@ proc getObject(temp: int): i3barData =
icon = ""
let text = "" & icon & " " & $temp & "°C"
let main_text = icon & " " & $temp & "°C"
- var data = newi3barData()
+ var data = newInfo()
data.title = "Temp : "
data.full_text = main_text
data.html_text = text
data.color = foreground
data.border = colour
+ data.selected_background = colour
+ data.selected_color = black
return data
proc main() =
diff --git a/i3bar_volume.nim b/volume.nim
similarity index 87%
rename from i3bar_volume.nim
rename to volume.nim
index dfc9254..25691bb 100644
--- a/i3bar_volume.nim
+++ b/volume.nim
@@ -2,7 +2,7 @@ import std/os
import strutils
import std/osproc
import std/math
-import i3bar_base
+import base
proc get_current_volume(): string {.gcsafe.}
@@ -48,14 +48,15 @@ proc get_volume*(run_once: bool = false) =
let vol = get_current_volume()
if vol != last_vol or true:
let (text, main_text) = getDesign(vol)
- let data = i3barData(
- title: "Volume : ",
- html_text: text,
- full_text: main_text,
- color: foreground,
- border: green,
- background: black
- )
+ var data = Info()
+ data.title = "Volume : "
+ data.html_text = text
+ data.full_text = main_text
+ data.color = foreground
+ data.border = green
+ data.background = black
+ data.selected_background = green
+ data.selected_color = black
let args = @["up", "down", "mute", "ncpamixer", "pavucontrol"]
let option = outputJSON(data,args)
case option:
diff --git a/i3bar_wlan.nim b/wlan.nim
old mode 100755
new mode 100644
similarity index 84%
rename from i3bar_wlan.nim
rename to wlan.nim
index 5bf2c7c..8575182
--- a/i3bar_wlan.nim
+++ b/wlan.nim
@@ -1,4 +1,4 @@
-import i3bar_base
+import base
import std/os
import std/osproc
import strutils
@@ -26,11 +26,13 @@ proc get_wifi(): (string, string) =
let quality = get_signal_quality()
return (essid, quality)
-proc getObject(conn: string): i3barData =
- var data = newi3barData()
+proc getObject(conn: string): Info =
+ var data = newInfo()
data.title = "WiFi : "
data.full_text = conn
data.border = purple
+ data.selected_background = purple
+ data.selected_color = black
return data
proc get_wifi_info*() =
@@ -50,12 +52,6 @@ proc get_wifi_info*() =
break
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):
get_wifi_info()