wmtools/date.nim

53 lines
1.2 KiB
Nim
Raw Normal View History

2022-04-28 21:58:40 +02:00
import base
import std/[times,osproc,re]
2022-02-06 21:10:06 +01:00
const default_bg = blue
const default_fg = white
const default_format = "yyyy-MM-dd"
const cal_pos_x = "20"
const cal_pos_y = "20"
2022-02-06 21:10:06 +01:00
2022-04-28 21:58:40 +02:00
proc getObject(date: string): Info =
var data = newInfo("Date")
data.full_text = date
data.border = default_bg
data.selected_bg = default_bg
data.selected_fg = default_fg
2022-02-06 21:10:06 +01:00
return data
proc newCalendar(): string =
var c = """yad --calendar \
--undecorated --fixed --close-on-unfocus --no-buttons \
--width="222" --height="193" \
2022-02-12 16:19:43 +01:00
--posx="%pos_x" --posy="%pos_y" \
--title="yad-calendar" --borders 0 > /dev/null
"""
return c
proc openCalendar*(input: i3barInput) =
var c = newCalendar()
2022-02-12 16:19:43 +01:00
c = replace(c,re"%pos_x", $(input.x - 111))
c = replace(c,re"%pos_y", $input.y)
discard execCmd(c)
2022-02-06 21:10:06 +01:00
proc dmenuCalendar() =
var c = newCalendar()
c = replace(c,re"%pos_x", cal_pos_x)
c = replace(c,re"%pos_y", cal_pos_y)
discard execCmd(c)
proc getDate*() =
let date_today = times.now().format(default_format)
let data = getObject(date_today)
let output = outputData(data)
if output == date_today:
dmenuCalendar()
2022-02-12 14:20:21 +01:00
2022-02-06 21:10:06 +01:00
proc main() =
getDate()
2022-02-06 21:10:06 +01:00
if isMainModule:
main()
2022-02-06 21:10:06 +01:00