more dmenu updates

This commit is contained in:
Paul Wilde 2022-04-28 12:50:07 +01:00
parent aabcfd98c7
commit 31f2b20d03
3 changed files with 48 additions and 27 deletions

View file

@ -1,10 +1,11 @@
import std/os
import std/[os,osproc]
import std/json
import std/rdstdin
import marshal
type
i3BarData* = object
title*: string
full_text*: string
short_text*: string
color*: string
@ -38,9 +39,13 @@ const darkgrey* = "#444"
const primary* = yellow
const secondary* = red
const alert* = "#bd2c40"
var loop* = true
var stoploop* = false
var dmenu* = false
proc newi3BarData*(): i3BarData =
return i3BarData(
title: "Info : ",
full_text: "",
short_text: "",
color: foreground,
@ -72,3 +77,23 @@ proc getArguments*(): seq[string] =
proc outputJSON*(data: i3barData) =
echo $$data
proc runDMenu*(data: i3BarData) =
var cmd = "echo " & $data.full_text & " | dmenu "
#cmd = cmd & " -l 2 "
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 & "\""
discard execCmd(cmd)
discard execCmd("i3-msg mode \"default\"")
let args = getArguments()
for arg in args:
if arg == "noloop":
stoploop = true
if arg == "dmenu":
stoploop = true
dmenu = true

View file

@ -72,6 +72,7 @@ proc get_minute(min: int): string =
proc getObject(time: string): i3barData =
var data = newi3barData()
data.title = "Fuzzy Time :"
data.full_text = time
#data.color = foreground
data.border = lightblue
@ -84,6 +85,9 @@ proc main() =
let time = get_fuzzytime()
if time != last_time:
let data = getObject(time)
if dmenu:
runDMenu(data)
break
outputJSON(data)
last_time = time

View file

@ -42,6 +42,7 @@ proc getObject(ping: float): i3barData =
col = red
let data = i3barData(
title: "Ping Clock:",
full_text: text,
color: col,
border: blue,
@ -50,40 +51,31 @@ proc getObject(ping: float): i3barData =
return data
proc runDMenu(data: i3BarData) =
var cmd = "echo Ping Clock : " & $data.full_text & " | dmenu "
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.background & "\""
cmd = cmd & " -sb \"" & $data.border & "\""
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 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)
var last_ping: float = 0
while loop:
let ping = get_ping()
if ping != last_ping:
let data = getObject(ping)
if dmenu:
runDMenu(data)
else:
outputJSON(data)
last_ping = ping
loop = not stoploop
if loop:
sleep(time_secs * 1000)
main()