wmtools/i3bar_base.nim

74 lines
1.5 KiB
Nim
Raw Normal View History

import std/os
import std/json
import std/rdstdin
2022-02-06 21:10:06 +01:00
import marshal
type
i3BarData* = object
full_text*: string
short_text*: string
color*: string
border*: string
2022-02-12 16:19:43 +01:00
background*: string
2022-02-06 21:10:06 +01:00
type
i3BarInput* = object
button*: int
2022-02-12 16:19:43 +01:00
x*: int
y*: int
2022-02-06 21:10:06 +01:00
const background* = "#000000"
const backgroundalt* = "#bb222222"
const backgroundalt2* = "#bb333333"
const foreground* = "#dfdfdf"
const foregroundalt* = "#777"
const foregroundalt2* = "#ccc"
2022-02-12 16:19:43 +01:00
const black* = "#000000"
2022-02-27 15:57:40 +01:00
const white* = "#FFFFFF"
2022-02-06 21:10:06 +01:00
const yellow* = "#ffb52a"
const red* = "#e60053"
const purple* = "#9f78e1"
const blue* = "#0a6cf5"
const lightblue* = "#7296EF"
const lighterblue* = "#B5DDF7"
const green* = "#4b9901"
const lightgreen* = "#00ff00"
const grey* = "#dfdfdf"
const darkgrey* = "#444"
const primary* = yellow
const secondary* = red
const alert* = "#bd2c40"
2022-02-27 15:57:40 +01:00
proc newi3BarData*(): i3BarData =
return i3BarData(
full_text: "",
short_text: "",
color: foreground,
border: white,
background: black
)
proc debugLog*(str: string) =
let f = open("/tmp/debug.txt",fmAppend)
defer: f.close()
f.writeLine(str)
proc parseInput*(): i3BarInput =
let input = readLineFromStdin("")
try:
let jsonNode = parseJson(input)
let i3input = to(jsonNode, i3BarInput)
return i3input
except:
return i3BarInput()
2022-02-12 14:20:21 +01:00
proc clearInput*(count: int = 1) =
2022-02-12 16:19:43 +01:00
for x in countup(1, count):
2022-02-12 14:20:21 +01:00
discard readLineFromStdin("")
2022-02-06 21:10:06 +01:00
proc getArguments*(): seq[string] =
let args = commandLineParams()
return args
proc outputJSON*(data: i3barData) =
echo $$data