Skip to content

Commit b6a6460

Browse files
Pomodoro: add CLI timer with countdown and pause/stop controls
1 parent 592db06 commit b6a6460

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Pomodoro Timer/main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import time
22

33

4-
def countdown(minutes, label):
4+
def countdown(minutes: int, label: str) -> None:
5+
"""Print a mm:ss countdown once per second for the given label."""
56
total_seconds = minutes * 60
6-
while total_seconds:
7+
while total_seconds >= 0:
78
mins, secs = divmod(total_seconds, 60)
8-
timer = f"{mins:02d}:{secs:02d}"
9-
print(f"{label} Timer: {timer}", end="\r")
9+
print(f"{label} Timer: {mins:02d}:{secs:02d}", end="\r")
1010
time.sleep(1)
1111
total_seconds -= 1
1212
print(f"\n{label} finished!")
1313

14-
15-
def handle_pause_stop():
14+
def handle_pause_stop() -> bool:
1615
while True:
1716
user_input = input(
1817
"\nPress 'p' to pause, 's' to stop, or 'Enter' to continue: "
@@ -69,4 +68,8 @@ def get_valid_input(prompt):
6968
long_break_minutes = get_valid_input("Enter long break interval in minutes: ")
7069
cycles = get_valid_input("Enter the number of cycles: ")
7170

72-
pomodoro_timer(work_minutes, short_break_minutes, long_break_minutes, cycles)
71+
while True:
72+
pomodoro_timer(work_minutes, short_break_minutes, long_break_minutes, cycles)
73+
# If user chose to repeat at the end, loop continues; otherwise we break here.
74+
if not repeat_or_end():
75+
break

0 commit comments

Comments
 (0)