Β« Oatmeal

πŸ… tiny tomato timer

Do you need a very tiny Pomodoro timer?

Here’s one I wrote in lua this morning.

-- 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()