Skip to content

Commit 6039961

Browse files
committed
add breaks_before_long option
1 parent b8361a0 commit 6039961

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lua/pomodoro/pomodoro.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local Phases = constants.Phases
1010
---@field work_duration number
1111
---@field break_duration number
1212
---@field long_break_duration number
13+
---@field breaks_before_long number
1314
---@field break_count number
1415
---@field timer_duration number
1516
---@field start_at_launch boolean
@@ -26,6 +27,7 @@ pomodoro.long_break_duration = 15 * MIN_IN_MS
2627
-- Delay duration in ms
2728
pomodoro.delay_duration = 1 * MIN_IN_MS
2829
pomodoro.break_count = 0
30+
pomodoro.breaks_before_long = 4
2931
pomodoro.timer_duration = 0
3032
pomodoro.start_at_launch = true
3133
pomodoro.timer = uv.new_timer()
@@ -63,7 +65,8 @@ end
6365

6466
---@return boolean
6567
function pomodoro.isInLongBreak()
66-
return pomodoro.break_count % 4 == 0 and pomodoro.phase == Phases.BREAK
68+
return pomodoro.break_count % (pomodoro.breaks_before_long + 1) == 0
69+
and pomodoro.phase == Phases.BREAK
6770
end
6871

6972
function pomodoro.startBreak()
@@ -97,6 +100,7 @@ end
97100

98101
function pomodoro.delayBreak()
99102
if pomodoro.phase == Phases.BREAK then
103+
info("Break delayed")
100104
pomodoro.phase = Phases.RUNNING
101105
-- So if a long break is delayed the next break is still a long one
102106
pomodoro.break_count = pomodoro.break_count - 1
@@ -139,6 +143,7 @@ end
139143
---@field break_duration? number
140144
---@field long_break_duration? number
141145
---@field delay_duration? number
146+
---@field breaks_before_long? number
142147
---@field start_at_launch? boolean
143148

144149
---@param opts PomodoroOpts
@@ -156,6 +161,9 @@ function pomodoro.setup(opts)
156161
if opts.delay_duration ~= nil then
157162
pomodoro.delay_duration = opts.delay_duration * MIN_IN_MS
158163
end
164+
if opts.breaks_before_long ~= nil then
165+
pomodoro.breaks_before_long = opts.breaks_before_long
166+
end
159167
if opts.start_at_launch ~= nil then
160168
pomodoro.start_at_launch = opts.start_at_launch
161169
end

lua/pomodoro/tests/pomodoro_spec.lua

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ describe("useless tests", function()
1010
opts.break_duration = 10
1111
opts.delay_duration = 10
1212
opts.long_break_duration = 15
13+
opts.breaks_before_long = 4
1314
opts.start_at_launch = false
1415
pomodoro.setup(opts)
16+
-- TODO: use the opts value directly
1517
assert(pomodoro.work_duration == 10 * MIN_IN_MS, "Opt work_duration")
1618
assert(pomodoro.break_duration == 10 * MIN_IN_MS, "Opt break_duration")
19+
assert(pomodoro.breaks_before_long == 4, "Opt breaks_before_long")
1720
assert(
1821
pomodoro.long_break_duration == 15 * MIN_IN_MS,
1922
"Opt long_break_duration"

0 commit comments

Comments
 (0)