Refactor 'pomo' script
parent
41568b9bc6
commit
07eec68706
76
.bin/pomo
76
.bin/pomo
|
@ -1,4 +1,5 @@
|
||||||
# /usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
# vim: set filetype=python:
|
||||||
"""
|
"""
|
||||||
Pomodoro timer
|
Pomodoro timer
|
||||||
|
|
||||||
|
@ -18,8 +19,47 @@ def clear():
|
||||||
os.system('echo -n "" > /tmp/pomo')
|
os.system('echo -n "" > /tmp/pomo')
|
||||||
|
|
||||||
|
|
||||||
|
def format_mins_secs(mins, secs):
|
||||||
|
return f"{mins:02d}:{secs:02d}"
|
||||||
|
|
||||||
|
|
||||||
|
def make_countdown():
|
||||||
|
def countdown(duration):
|
||||||
|
while duration != 0:
|
||||||
|
mins = duration // 60
|
||||||
|
secs = duration % 60
|
||||||
|
time_str = format_mins_secs(mins, secs)
|
||||||
|
os.system(f'echo -n "{time_str}" > /tmp/pomo')
|
||||||
|
sleep(1)
|
||||||
|
duration -= 1
|
||||||
|
return countdown
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
atexit.register(clear)
|
atexit.register(clear)
|
||||||
|
|
||||||
|
prep_duration = args.prep_duration * 60
|
||||||
|
work_duration = args.work_duration * 60
|
||||||
|
break_duration = args.break_duration * 60
|
||||||
|
repeats = args.repeats
|
||||||
|
|
||||||
|
prep_countdown = make_countdown()
|
||||||
|
work_countdown = make_countdown()
|
||||||
|
break_countdown = make_countdown()
|
||||||
|
|
||||||
|
prep_countdown(prep_duration)
|
||||||
|
|
||||||
|
while repeats != 0:
|
||||||
|
notification.notify(title="Get started")
|
||||||
|
work_countdown(work_duration)
|
||||||
|
if break_duration != 0:
|
||||||
|
notification.notify(title="Time for a break")
|
||||||
|
break_countdown(break_duration)
|
||||||
|
notification.notify(title="Break is over, back to work")
|
||||||
|
repeats -= 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument('-p', '--prep-duration', type=int,
|
parser.add_argument('-p', '--prep-duration', type=int,
|
||||||
|
@ -33,36 +73,4 @@ parser.add_argument('-r', '--repeats', type=int,
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
prep_duration = args.prep_duration * 60
|
main(args)
|
||||||
work_duration = args.work_duration * 60
|
|
||||||
break_duration = args.break_duration * 60
|
|
||||||
repeats = args.repeats
|
|
||||||
|
|
||||||
|
|
||||||
def make_countdown(color="#000000"):
|
|
||||||
def countdown(duration):
|
|
||||||
while duration != 0:
|
|
||||||
mins = duration // 60
|
|
||||||
secs = duration % 60
|
|
||||||
# os.system('echo -n "{:s} {:02d}:{:02d} \x01" > /tmp/pomo'.format(color, mins, secs))
|
|
||||||
os.system(
|
|
||||||
'echo -n "<fc={:s}> {:02d}:{:02d} </fc>" > /tmp/pomo'.format(color, mins, secs))
|
|
||||||
sleep(1)
|
|
||||||
duration -= 1
|
|
||||||
return countdown
|
|
||||||
|
|
||||||
|
|
||||||
prep_countdown = make_countdown("#0000aa")
|
|
||||||
work_countdown = make_countdown("#aa0000")
|
|
||||||
break_countdown = make_countdown("#00bb00")
|
|
||||||
|
|
||||||
prep_countdown(prep_duration)
|
|
||||||
|
|
||||||
while repeats != 0:
|
|
||||||
notification.notify(title="Get started")
|
|
||||||
work_countdown(work_duration)
|
|
||||||
if break_duration != 0:
|
|
||||||
notification.notify(title="Time for a break")
|
|
||||||
break_countdown(break_duration)
|
|
||||||
notification.notify(title="Break is over, back to work")
|
|
||||||
repeats -= 1
|
|
||||||
|
|
Loading…
Reference in New Issue