2022-04-28 21:58:40 +02:00
|
|
|
import base
|
2022-07-08 13:19:53 +02:00
|
|
|
import std/[times,osproc,re]
|
2022-02-06 21:10:06 +01:00
|
|
|
|
2022-05-04 17:17:02 +02: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 =
|
2022-05-04 17:17:02 +02:00
|
|
|
var data = newInfo("Date")
|
2022-04-28 16:52:45 +02:00
|
|
|
data.full_text = date
|
2022-05-04 17:17:02 +02:00
|
|
|
data.border = default_bg
|
|
|
|
data.selected_bg = default_bg
|
|
|
|
data.selected_fg = default_fg
|
2022-02-06 21:10:06 +01:00
|
|
|
return data
|
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
proc newCalendar(): string =
|
2022-02-06 23:07:32 +01:00
|
|
|
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" \
|
2022-02-06 23:07:32 +01:00
|
|
|
--title="yad-calendar" --borders 0 > /dev/null
|
|
|
|
"""
|
2022-04-28 16:52:45 +02:00
|
|
|
return c
|
2022-05-04 17:17:02 +02:00
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
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)
|
2022-02-06 23:07:32 +01:00
|
|
|
discard execCmd(c)
|
2022-02-06 21:10:06 +01:00
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
proc dmenuCalendar() =
|
|
|
|
var c = newCalendar()
|
2022-05-04 17:17:02 +02:00
|
|
|
c = replace(c,re"%pos_x", cal_pos_x)
|
|
|
|
c = replace(c,re"%pos_y", cal_pos_y)
|
2022-04-28 16:52:45 +02:00
|
|
|
discard execCmd(c)
|
|
|
|
|
|
|
|
proc getDate*() =
|
2022-05-04 17:17:02 +02:00
|
|
|
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() =
|
2022-04-28 16:52:45 +02:00
|
|
|
getDate()
|
|
|
|
|
2022-02-06 21:10:06 +01:00
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
if isMainModule:
|
|
|
|
main()
|
2022-02-06 21:10:06 +01:00
|
|
|
|