tm-timer 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: tm-timer
3
+ Version: 1.0.0
4
+ Summary: Terminal timer with pause/resume and alert
5
+ Author: ph4nt01
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Environment :: Console
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Requires-Python: >=3.6
10
+ Dynamic: author
11
+ Dynamic: classifier
12
+ Dynamic: requires-python
13
+ Dynamic: summary
@@ -0,0 +1,24 @@
1
+ # In The Name of God
2
+
3
+ ## tm ⏱ Terminal Timer
4
+
5
+ Minimalistic Terminal-based timer.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install git+https://github.com/Ph4nt01/timer.git
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ tm 10s
17
+ tm 25m
18
+ tm 1h30m45s
19
+
20
+ p — Pause/Resume
21
+ q — Quit early
22
+
23
+ ```
24
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="tm-timer",
5
+ version="1.0.0",
6
+ packages=find_packages(),
7
+ entry_points={
8
+ "console_scripts": [
9
+ "tm = tm_timer.cli:entry"
10
+ ]
11
+ },
12
+ description="Terminal timer with pause/resume and alert",
13
+ author="ph4nt01",
14
+ python_requires=">=3.6",
15
+ classifiers=[
16
+ "Programming Language :: Python :: 3",
17
+ "Environment :: Console",
18
+ "Operating System :: POSIX :: Linux",
19
+ ]
20
+ )
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,102 @@
1
+ import time
2
+ import threading
3
+ import sys
4
+ import termios
5
+ import tty
6
+ import re
7
+ import os
8
+ import atexit
9
+ import shutil
10
+ import argparse
11
+
12
+ original_term_settings = termios.tcgetattr(sys.stdin.fileno())
13
+
14
+ def restore_terminal():
15
+ try:
16
+ termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, original_term_settings)
17
+ except:
18
+ pass
19
+
20
+ atexit.register(restore_terminal)
21
+
22
+ def with_raw_mode():
23
+ fd = sys.stdin.fileno()
24
+ old_settings = termios.tcgetattr(fd)
25
+ tty.setraw(fd)
26
+ return old_settings
27
+
28
+ def get_char():
29
+ fd = sys.stdin.fileno()
30
+ old_settings = with_raw_mode()
31
+ try:
32
+ ch = sys.stdin.read(1)
33
+ finally:
34
+ termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
35
+ return ch
36
+
37
+ def parse_time_input(user_input):
38
+ pattern = r"(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?"
39
+ match = re.fullmatch(pattern, user_input.strip().lower())
40
+ if not match or not any(match.groups()):
41
+ raise ValueError("Invalid time format. Use format like '1h30m45s'.")
42
+ hours = int(match.group(1)) if match.group(1) else 0
43
+ minutes = int(match.group(2)) if match.group(2) else 0
44
+ seconds = int(match.group(3)) if match.group(3) else 0
45
+ return hours * 3600 + minutes * 60 + seconds
46
+
47
+ def timer():
48
+ global paused, running, seconds, target_seconds
49
+ while running:
50
+ if not paused:
51
+ cols = shutil.get_terminal_size((80, 20)).columns
52
+ mins, secs = divmod(seconds, 60)
53
+ hours, mins = divmod(mins, 60)
54
+ msg = f"Timer: {hours:02d}:{mins:02d}:{secs:02d} [Press 'p' to Pause/Resume, 'q' to Quit]"
55
+ msg = msg[:cols - 1] if len(msg) >= cols else msg
56
+ sys.stdout.write(f"\r\033[K{msg}")
57
+ sys.stdout.flush()
58
+ seconds += 1
59
+ if seconds >= target_seconds:
60
+ sys.stdout.write("\n\n⏰ Time's up! Target of {} reached.\n".format(target_input))
61
+ sys.stdout.flush()
62
+ running = False
63
+ break
64
+ time.sleep(1)
65
+
66
+ def input_listener():
67
+ global paused, running
68
+ while running:
69
+ key = get_char()
70
+ if key.lower() == 'p':
71
+ paused = not paused
72
+ elif key.lower() == 'q':
73
+ running = False
74
+ break
75
+
76
+ def entry():
77
+ global paused, running, seconds, target_seconds, target_input
78
+
79
+ parser = argparse.ArgumentParser(description="Terminal Timer with pause and alert.")
80
+ parser.add_argument("duration", help="Timer duration (e.g., 4h, 25m, 1h30m45s)")
81
+ args = parser.parse_args()
82
+
83
+ try:
84
+ target_input = args.duration
85
+ target_seconds = parse_time_input(target_input)
86
+ except ValueError as e:
87
+ print(e)
88
+ sys.exit(1)
89
+
90
+ paused = False
91
+ running = True
92
+ seconds = 0
93
+
94
+ input_thread = threading.Thread(target=input_listener, daemon=True)
95
+ timer_thread = threading.Thread(target=timer)
96
+
97
+ input_thread.start()
98
+ timer_thread.start()
99
+
100
+ timer_thread.join()
101
+ restore_terminal()
102
+ print("Timer stopped.")
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: tm-timer
3
+ Version: 1.0.0
4
+ Summary: Terminal timer with pause/resume and alert
5
+ Author: ph4nt01
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Environment :: Console
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Requires-Python: >=3.6
10
+ Dynamic: author
11
+ Dynamic: classifier
12
+ Dynamic: requires-python
13
+ Dynamic: summary
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ timer/__init__.py
4
+ timer/cli.py
5
+ tm_timer.egg-info/PKG-INFO
6
+ tm_timer.egg-info/SOURCES.txt
7
+ tm_timer.egg-info/dependency_links.txt
8
+ tm_timer.egg-info/entry_points.txt
9
+ tm_timer.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tm = tm_timer.cli:entry
@@ -0,0 +1 @@
1
+ timer