Skip to content

Commit 7877082

Browse files
committed
add get_pomodoro_status
1 parent 21c3b6c commit 7877082

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lua/pomodoro/pomodoro.lua

+20
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ function pomodoro.startTimer(time, fn)
4343
pomodoro.timer:start(time, 0, fn)
4444
end
4545

46+
function pomodoro.get_pomodoro_status()
47+
local time_left = pomodoro.timer_duration
48+
- (uv.now() - pomodoro.started_timer_time)
49+
50+
local phase_str = ""
51+
if pomodoro.phase == Phases.NOT_RUNNING then
52+
phase_str = "Not Running"
53+
elseif pomodoro.phase == Phases.RUNNING then
54+
phase_str = "Work"
55+
elseif pomodoro.phase == Phases.BREAK then
56+
phase_str = "Break"
57+
end
58+
59+
local minutes = math.floor(time_left / 60000)
60+
local seconds = math.floor((time_left % 60000) / 1000)
61+
local time_left_str = string.format("%02d:%02d", minutes, seconds)
62+
63+
return phase_str .. " " .. time_left_str
64+
end
65+
4666
function pomodoro.displayPomodoroUI()
4767
if pomodoro.phase == Phases.NOT_RUNNING or pomodoro.phase == nil then
4868
pomodoro.start()

0 commit comments

Comments
 (0)