Skip to content

Instantly share code, notes, and snippets.

@eli-oat

eli-oat/pomodoro.lua

Last active Apr 19, 2020
Embed
What would you like to do?
A teeny tiny pomodoro timer
-- title: pomo
-- author: eli_oat
-- about: a very tiny pomodoro timer
defaults = {
pomoTime = 1500, -- length of a pomodoro in seconds
restTime = 600, -- length of a short rest in seconds
longRestTime = 900, -- length of a long rest in secconds
pomoCount = 0, -- tracks the number of elapsed pomodoros
pomoTarget = 4 -- target number of pomodoros
}
pomoTime = defaults.pomoTime
restTime = defaults.restTime
longRestTime = defaults.longRestTime
pomoCount = defaults.pomoCount
pomoTarget = defaults.pomoTarget
function sleep (a)
local sec = tonumber(os.clock() + a)
while (os.clock() < sec) do
end
end
function prettyTime (timeInSeconds)
local minutes = math.floor(timeInSeconds / 60)
local seconds = timeInSeconds % 60
local timeDisplay = string.format('%02d:%02d', minutes, seconds)
return timeDisplay
end
function pomo ()
repeat
io.write('🍅 ' .. prettyTime(pomoTime) .. '\n')
pomoTime = pomoTime - 1
sleep(1)
until pomoTime == 0
while pomoTime == 0 and pomoCount < pomoTarget do
io.write('😴 ' .. prettyTime(restTime) .. '\n')
restTime = restTime - 1
sleep(1)
while restTime == 0 do
restTime = defaults.restTime
pomoTime = defaults.pomoTime
pomoCount = pomoCount + 1
pomo()
end
end
while pomoCount == pomoTarget do
io.write('🍹 LONG REST! ' .. prettyTime(longRestTime) .. '\n')
longRestTime = longRestTime - 1
sleep(1)
while longRestTime == 0 do
restTime = defaults.restTime
pomoTime = defaults.pomoTime
longRestTime = defaults.longRestTime
pomoCount = defaults.pomoCount
pomo()
end
end
end
pomo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.