-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpomo.fnl
More file actions
63 lines (51 loc) · 1.59 KB
/
pomo.fnl
File metadata and controls
63 lines (51 loc) · 1.59 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
(local c coroutine)
(local config-default (require :defaults))
(local config-path (.. (os.getenv :HOME)))
(local config-file :/.pomo-config.fnl)
(local load-config (require :load-config))
(local config (load-config
(.. config-path config-file)
config-default))
;; wrapper for coroutine.resume
;; takes a producer and returns the value resumed from it
(fn receive [prod]
(let [(_ x) (c.resume prod)] x))
;; wrapper for coroutine.yield
;; takes a value and yields it
;; must be called from within a coroutine
(fn send [...] (c.yield [...]))
(fn sleep []
(os.execute (.. "sleep " 1)))
(fn pretty-time [s]
(let [minutes (math.floor (/ s 60))
seconds (% s 60)]
(string.format "%02d:%02d" minutes seconds)))
(fn producer []
(c.create (fn []
(for [i 1 config.max-pomos 1]
(for [i config.focus-time 1 -1]
(send i :focus))
(when (< i config.max-pomos)
(if (= (% i 4) 0)
(for [i config.long-rest-time 1 -1] (send i :long-rest))
(for [i config.short-rest-time 1 -1] (send i :short-rest))))))))
(fn filter [prod]
(c.create (fn []
(while (~= "dead" (c.status prod))
(match (receive prod)
([time config-keystem] ? (~= time nil))
(let [emoji (. config (.. config-keystem :-emoji))
time (pretty-time time)]
(send (.. emoji " " time " " emoji))))))))
(fn consumer [prod]
(while (~= "dead" (c.status prod))
(match (receive prod)
([x] ? (~= x nil))
(do
(print x)
(sleep))))
(print "🏁 POMODORO COMPLETE 🏁"))
(->
(producer)
(filter)
(consumer))