@@ -9,6 +9,9 @@ local Phases = constants.Phases
9
9
--- @class Pomodoro
10
10
--- @field work_duration number
11
11
--- @field break_duration number
12
+ --- @field long_break_duration number
13
+ --- @field breaks_before_long number
14
+ --- @field break_count number
12
15
--- @field timer_duration number
13
16
--- @field start_at_launch boolean
14
17
--- @field timer uv_timer_t
@@ -19,8 +22,12 @@ local pomodoro = {}
19
22
pomodoro .work_duration = 25 * MIN_IN_MS
20
23
-- Break duration in ms
21
24
pomodoro .break_duration = 5 * MIN_IN_MS
25
+ -- Break duration in ms
26
+ pomodoro .long_break_duration = 15 * MIN_IN_MS
22
27
-- Delay duration in ms
23
28
pomodoro .delay_duration = 1 * MIN_IN_MS
29
+ pomodoro .break_count = 0
30
+ pomodoro .breaks_before_long = 4
24
31
pomodoro .timer_duration = 0
25
32
pomodoro .start_at_launch = true
26
33
pomodoro .timer = uv .new_timer ()
@@ -56,11 +63,25 @@ function pomodoro.closePomodoroUi()
56
63
UI .close ()
57
64
end
58
65
66
+ --- @return boolean
67
+ function pomodoro .isInLongBreak ()
68
+ return pomodoro .break_count % (pomodoro .breaks_before_long + 1 ) == 0
69
+ and pomodoro .phase == Phases .BREAK
70
+ end
71
+
59
72
function pomodoro .startBreak ()
60
- info (" Break of " .. pomodoro .break_duration / MIN_IN_MS .. " m started!" )
61
73
pomodoro .phase = Phases .BREAK
74
+ pomodoro .break_count = pomodoro .break_count + 1
75
+ local break_duration
76
+ if pomodoro .isInLongBreak () then
77
+ break_duration = pomodoro .long_break_duration
78
+ else
79
+ break_duration = pomodoro .break_duration
80
+ end
81
+
82
+ info (" Break of " .. break_duration / MIN_IN_MS .. " m started!" )
62
83
vim .schedule (pomodoro .displayPomodoroUI )
63
- pomodoro .startTimer (pomodoro . break_duration , pomodoro .endBreak )
84
+ pomodoro .startTimer (break_duration , pomodoro .endBreak )
64
85
end
65
86
66
87
function pomodoro .endBreak ()
79
100
80
101
function pomodoro .delayBreak ()
81
102
if pomodoro .phase == Phases .BREAK then
103
+ info (" Break delayed" )
82
104
pomodoro .phase = Phases .RUNNING
105
+ -- So if a long break is delayed the next break is still a long one
106
+ pomodoro .break_count = pomodoro .break_count - 1
83
107
pomodoro .closePomodoroUi ()
84
108
pomodoro .startTimer (MIN_IN_MS , pomodoro .startBreak )
85
109
end
117
141
--- @class PomodoroOpts
118
142
--- @field work_duration ? number
119
143
--- @field break_duration ? number
144
+ --- @field long_break_duration ? number
120
145
--- @field delay_duration ? number
146
+ --- @field breaks_before_long ? number
121
147
--- @field start_at_launch ? boolean
122
148
123
149
--- @param opts PomodoroOpts
@@ -129,9 +155,15 @@ function pomodoro.setup(opts)
129
155
if opts .break_duration ~= nil then
130
156
pomodoro .break_duration = opts .break_duration * MIN_IN_MS
131
157
end
158
+ if opts .long_break_duration ~= nil then
159
+ pomodoro .long_break_duration = opts .long_break_duration * MIN_IN_MS
160
+ end
132
161
if opts .delay_duration ~= nil then
133
162
pomodoro .delay_duration = opts .delay_duration * MIN_IN_MS
134
163
end
164
+ if opts .breaks_before_long ~= nil then
165
+ pomodoro .breaks_before_long = opts .breaks_before_long
166
+ end
135
167
if opts .start_at_launch ~= nil then
136
168
pomodoro .start_at_launch = opts .start_at_launch
137
169
end
0 commit comments