Skip to content

Commit 9786701

Browse files
authored
Merge pull request #796 from ttafsir/PCC52
Pcc52
2 parents f8ea2e0 + c600680 commit 9786701

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

52/ttafsir/pomodoro.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from rich.console import Console
2+
from rich.live import Live
3+
from time import sleep
4+
from datetime import timedelta
5+
6+
7+
console = Console()
8+
9+
10+
class PomodoroTimer:
11+
def __init__(self, start_timer=25, break_timer=5):
12+
self._timer = start_timer
13+
self._break = break_timer
14+
self._countdown = timedelta(minutes=self._timer)
15+
16+
def run(self, prompt="TIMER"):
17+
with Live(auto_refresh=False) as live:
18+
while self._countdown:
19+
console.print(f"{prompt}: {self._countdown}", end="\r")
20+
self._countdown += timedelta(seconds=-1)
21+
sleep(1)
22+
live.refresh()
23+
24+
def restart(self, start_timer, prompt):
25+
self._countdown = timedelta(minutes=start_timer)
26+
self.run(prompt)
27+
28+
29+
timer_duration = int(input("Duration: ").strip())
30+
break_duration = int(input("Break Duration: ").strip())
31+
console.print("\nCTRL+C to quit")
32+
while True:
33+
try:
34+
timer = PomodoroTimer(start_timer=timer_duration)
35+
timer.run()
36+
timer.restart(start_timer=break_duration, prompt="BREAK")
37+
except KeyboardInterrupt:
38+
console.print("TIME'S UP")
39+
break

0 commit comments

Comments
 (0)