Skip to content

Commit 4c51c7f

Browse files
Add Pomodoro Timer CLI tool in Python (76 lines)
A terminal-based Pomodoro Timer with live countdown, progress bar, and automatic cycling between work sessions and breaks. Uses only Python standard library. Merged from PR #555 Co-authored-by: Kishore Gowthaman <kishore2k05@users.noreply.github.com>
1 parent e817848 commit 4c51c7f

2 files changed

Lines changed: 145 additions & 0 deletions

File tree

pomodoro-Timer/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# 🍅 Pomodoro Timer
2+
3+
A terminal-based Pomodoro Timer that helps you stay focused using the [Pomodoro Technique](https://en.wikipedia.org/wiki/Pomodoro_Technique).
4+
5+
## 📸 Preview
6+
7+
```
8+
╔══════════════════════════════════════╗
9+
║ 🍅 POMODORO TIMER 🍅 ║
10+
╚══════════════════════════════════════╝
11+
12+
Phase : 🔴 FOCUS — Work Session
13+
Cycle : 1 / 4
14+
15+
Time : 24:13
16+
17+
[████████████░░░░░░░░░░░░░░░░░░] 40%
18+
19+
Press Ctrl+C to quit.
20+
```
21+
22+
## ⏱️ How It Works
23+
24+
The Pomodoro Technique breaks work into focused intervals:
25+
26+
| Phase | Duration |
27+
|--------------|-----------|
28+
| Work session | 25 minutes |
29+
| Short break | 5 minutes |
30+
| Long break | 15 minutes (after every 4 cycles) |
31+
32+
## 🚀 Installation
33+
34+
No external libraries required — uses only Python's standard library.
35+
36+
```bash
37+
git clone https://github.com/YOUR_USERNAME/100LinesOfCode.git
38+
cd 100LinesOfCode/Pomodoro-Timer
39+
```
40+
41+
## ▶️ Usage
42+
43+
```bash
44+
python pomodoro.py
45+
```
46+
47+
- Press **Enter** to start/continue each phase
48+
- Press **Ctrl+C** at any time to quit
49+
50+
## ⚙️ Customization
51+
52+
Edit the config at the top of `pomodoro.py`:
53+
54+
```python
55+
WORK_MINS = 25 # Work session length
56+
SHORT_BREAK = 5 # Short break length
57+
LONG_BREAK = 15 # Long break length
58+
CYCLES_BEFORE_LONG = 4 # Cycles before a long break
59+
```
60+
61+
## 🛠️ Technologies
62+
63+
- Python 3.x
64+
- Standard library only (`time`, `sys`, `os`)
65+
66+
## 📏 Lines of Code
67+
68+
**81 lines** (excluding comments and blank lines)

pomodoro-Timer/pomodoro.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import time
2+
import sys
3+
import os
4+
5+
WORK_MINS = 25
6+
SHORT_BREAK = 5
7+
LONG_BREAK = 15
8+
CYCLES_BEFORE_LONG = 4
9+
10+
def beep(times=3):
11+
for _ in range(times):
12+
print("\a", end="", flush=True)
13+
time.sleep(0.3)
14+
15+
def clear():
16+
os.system("cls" if os.name == "nt" else "clear")
17+
18+
def format_time(seconds):
19+
m, s = divmod(seconds, 60)
20+
return f"{m:02d}:{s:02d}"
21+
22+
def countdown(label, duration_mins, cycle_info=""):
23+
total = duration_mins * 60
24+
bar_width = 30
25+
26+
for remaining in range(total, -1, -1):
27+
elapsed = total - remaining
28+
filled = int(bar_width * elapsed / total)
29+
bar = "█" * filled + "░" * (bar_width - filled)
30+
pct = int(100 * elapsed / total)
31+
32+
clear()
33+
print("╔══════════════════════════════════════╗")
34+
print("║ 🍅 POMODORO TIMER 🍅 ║")
35+
print("╚══════════════════════════════════════╝")
36+
print(f"\n Phase : {label}")
37+
if cycle_info:
38+
print(f" Cycle : {cycle_info}")
39+
print(f"\n Time : {format_time(remaining)}")
40+
print(f"\n [{bar}] {pct}%\n")
41+
print(" Press Ctrl+C to quit.\n")
42+
43+
if remaining > 0:
44+
time.sleep(1)
45+
46+
beep(3)
47+
48+
def run():
49+
cycle = 0
50+
print("\n Welcome to Pomodoro Timer!")
51+
print(f" Work: {WORK_MINS}m | Short break: {SHORT_BREAK}m | Long break: {LONG_BREAK}m\n")
52+
input(" Press Enter to start your first session...")
53+
54+
while True:
55+
cycle += 1
56+
info = f"{cycle} / {CYCLES_BEFORE_LONG}"
57+
countdown("🔴 FOCUS — Work Session", WORK_MINS, info)
58+
print("\n ✅ Work session complete!\n")
59+
60+
61+
if cycle % CYCLES_BEFORE_LONG == 0:
62+
print(f" 🎉 {CYCLES_BEFORE_LONG} cycles done! Time for a long break.\n")
63+
input(" Press Enter to start your long break...")
64+
countdown("🟢 LONG BREAK", LONG_BREAK)
65+
else:
66+
input(" Press Enter to start your short break...")
67+
countdown("🟡 SHORT BREAK", SHORT_BREAK)
68+
69+
print("\n Break over! Ready for the next session?\n")
70+
input(" Press Enter to continue...\n")
71+
72+
if __name__ == "__main__":
73+
try:
74+
run()
75+
except KeyboardInterrupt:
76+
print("\n\n 👋 Session ended. Great work!\n")
77+
sys.exit(0)

0 commit comments

Comments
 (0)