|
1 | 1 | import time |
2 | 2 |
|
3 | 3 |
|
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.""" |
5 | 6 | total_seconds = minutes * 60 |
6 | | - while total_seconds: |
| 7 | + while total_seconds >= 0: |
7 | 8 | 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") |
10 | 10 | time.sleep(1) |
11 | 11 | total_seconds -= 1 |
12 | 12 | print(f"\n{label} finished!") |
13 | 13 |
|
14 | | - |
15 | | -def handle_pause_stop(): |
| 14 | +def handle_pause_stop() -> bool: |
16 | 15 | while True: |
17 | 16 | user_input = input( |
18 | 17 | "\nPress 'p' to pause, 's' to stop, or 'Enter' to continue: " |
@@ -69,4 +68,8 @@ def get_valid_input(prompt): |
69 | 68 | long_break_minutes = get_valid_input("Enter long break interval in minutes: ") |
70 | 69 | cycles = get_valid_input("Enter the number of cycles: ") |
71 | 70 |
|
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