pomo/pomo

173 lines
2.5 KiB
Lua
Executable File

#! /usr/bin/env lua
-- requires sox to play bell sound
local alt_getopt = require 'alt_getopt'
local term = require 'term'
local times = 4
local nb = false -- "no break"
local long_opts = {
help = "h",
times = "t",
nobreak = "n"
}
local short_opt
local optarg
local startTime = os.time()
local tic = 1
local endTime = startTime+10 --10 seconds
local pomodoro = 25*60
local breaktime = 5*60
local longbreak = 20*60
local i
function print_help()
print([[
NAME
pomo - pomodoro method timer
SYNOPSIS
pomo [OPTION] [ARGUMENT]
DESCRIPTION
-t --times <amount>
amount of pomodoros to run. Default = 4
-n --nobreak
suppresses 5 minute break timer after completing a pomodoro
-h --help
this help text
NO COPYRIGHT
Unlicense 2023 exquisitecorp
]])
os.exit()
end
function _process_args()
short_opt,optarg = alt_getopt.get_opts (arg, "t:hn", long_opts)
for k,v in pairs (short_opt) do
--print("opt: " .. k .. " value: " .. v)
--
if k=="t" then
if type(tonumber(v)) == "number" then
--print("valid number")
times = tonumber(v)
print("Beginning session of " .. times .. " pomodoros.")
else
print("Times specified not a valid number")
print_help()
end
elseif k=="h" then
print_help()
elseif k=="n" then
nb = true
end
end
end
function bell()
--Play a bell sound if we have sox installed, via the shell
os.execute("play -n synth 2 sin 960 fade l 0 1 0.9")
end
function toMin(seconds)
--rounding up to the nearest minute
return math.ceil(seconds/60)
end
function wait(seconds)
local start = os.time()
repeat
--waiting here
until os.time() > startTime + tic
i=i-1
startTime = startTime + tic
term.cleareol()
print("Minutes: "..toMin(i))
end
function _pomodoro()
term.cleareol()
print("🍅")
print("Starting 25 minute pomodoro")
i = pomodoro
repeat
wait()
term.cursor.goup(1)
until i <= 0
end
function _break()
print("Starting 5 minute break")
i = breaktime
repeat
wait()
term.cursor.goup(1)
until i <= 0
end
function _longbreak()
print("Starting 20 minute break")
i = longbreak
repeat
wait()
term.cursor.group(1)
until i<= 0
end
----------------- start ----------------
_process_args()
for poms = 1,times
do
_pomodoro()
bell()
if poms==4 and not nb then
_longbreak()
elseif poms~=4 and not nb then
_break()
end
bell()
end
print(times .. " pomodoros completed.")