changes to remove i3bar priority

This commit is contained in:
Paul Wilde 2022-04-28 20:58:40 +01:00
parent 89b73b613c
commit 1c0843d915
18 changed files with 82 additions and 124 deletions

View file

@ -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)

11
i3bar_battery.nim → battery.nim Executable file → Normal file
View file

@ -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 = "<span foreground=\"" & icon_colour & "\">" & icon & "</span>" & $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

View file

@ -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:

View file

@ -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) =

View file

@ -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

View file

@ -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()

View file

@ -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()

View file

View file

@ -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) =

View file

@ -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

View file

@ -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 = "<span foreground='" & colour & "'>" & icon & "</span> " & $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() =

View file

@ -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:

14
i3bar_wlan.nim → wlan.nim Executable file → Normal file
View file

@ -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()