-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock
More file actions
executable file
·124 lines (105 loc) · 2.48 KB
/
clock
File metadata and controls
executable file
·124 lines (105 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env lua
-- luarocks: luautf8 lcurses sleep xml
local C = require 'curses'
local Enum = require 'enum'
local LED = require 'led'
local paint = require 'paint'
local sleep = require 'sleep'
local states = Enum({'running', 'paused'})
local state = states.running
local function rectangles_of (str, fill_char)
local rectangles = {}
local d
for c in str:gmatch('.') do
if c == ':' then
d = LED.colon:gsub('%S', fill_char)
else
d = LED.digit(tonumber(c, 16), fill_char)
-- print(string.format('%x', 16))
end
if d ~= nil then
rectangles[#rectangles+1] = d
end
end
return rectangles
end
local _, digit_height = paint.dim(LED.digit(0, '@'))
-- positioning: tune to taste
local l_zero, c_zero, c_space = 8, 6, 6
local l_blips = l_zero + digit_height + 3
local blip, noblip, blip_stride = '@@@@@@', ' ', 3
local function update_blip (scr, sec, str)
local c = c_zero + blip_stride*(sec - 1)
if sec > 0 then
scr:mvaddstr(l_blips, c, str)
scr:mvaddstr(l_blips+1, c-1, str)
end
end
local function paint_markers (scr)
local marker_sm, marker_lg, seconds_interval = " @\n@@", " @\n@@\n@@", 5
local markers = {}
for i = 1, 60/seconds_interval - 1 do
if i % 2 == 0 then
markers[i] = marker_lg
else
markers[i] = marker_sm
end
end
-- l = l_blips + blip-height + 1
-- space = blip_stride * seconds_interval - marker-width
paint.rectangles(scr, l_blips + 3, c_zero + 10, markers, blip_stride * seconds_interval - 2)
end
C.initscr()
C.cbreak()
C.echo(false)
local scr = C.stdscr()
scr:nodelay(true)
local keys = {
pause = string.byte('p'),
quit = string.byte('q'),
}
local key
local sec0, sec1 = 60
local function main ()
while true do
if state == states.running then
sec1 = os.time() % 60
if sec1 < sec0 then
scr:clear()
paint_markers(scr)
local hour = os.date('*t').hour % 12
if hour == 0 then
hour = 12
end
hour = string.format('%x', hour)
paint.rectangles(scr, l_zero, c_zero, rectangles_of(os.date(hour .. ':%M'), '@'), c_space)
else
update_blip(scr, sec0, noblip)
end
update_blip(scr, sec1, blip)
scr:move(0, 0)
scr:refresh()
end
key = scr:getch()
if key == keys.quit then
break
end
if key == keys.pause then
if state == states.running then
state = states.pause
else
state = states.running
end
end
if state == states.running then
sec0 = sec1
sleep(1000)
end
end
end
local function err (err)
C.endwin()
print(debug.traceback(err, 2))
os.exit(2)
end
xpcall(main, err)