File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 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 ("\n CTRL+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
You can’t perform that action at this time.
0 commit comments