summaryrefslogtreecommitdiff
path: root/timers.py
diff options
context:
space:
mode:
authorhmj6502 <hashim@hmj6502.com>2025-12-28 13:35:02 +0000
committerhmj6502 <hashim@hmj6502.com>2025-12-28 13:35:02 +0000
commitb5d036762d9e4566f81e18708414fd306db6a1bc (patch)
treec1fcae8ad1558a01d03906fbe98285a19e925404 /timers.py
parent1dd32f5dd7bb228713206389646c54edfd585b0a (diff)
downloadlock-n-log-b5d036762d9e4566f81e18708414fd306db6a1bc.tar.gz
lock-n-log-b5d036762d9e4566f81e18708414fd306db6a1bc.tar.bz2
lock-n-log-b5d036762d9e4566f81e18708414fd306db6a1bc.zip
INCOMPLETE: add stop/start and rest bank to stopwatch
- IMPORTANT: added seconds to timestamp in csv as someone could start and rest in the same minute - BROKEN commit, but i need something sane to be able to roll back to - only works for stopwatch atm, haven't even tested timer - doesn't show cumalative time focused in timer, will need a bit of refactoring (hence need for sane commit) - timer now returns seconds for everything except start
Diffstat (limited to 'timers.py')
-rw-r--r--timers.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/timers.py b/timers.py
index cf8e91d..5ba51fa 100644
--- a/timers.py
+++ b/timers.py
@@ -4,7 +4,7 @@ import inputs
frequency = 120 # 120Hz refresh
-def timer(length=0):
+def timer(length=0, ratio = 0.2, rest_accum=0):
"""countdown and stopwatch; pass length as 0 for stopwatch"""
start = datetime.datetime.now()
end = start + datetime.timedelta(seconds=length) # change to mins in final
@@ -16,12 +16,16 @@ def timer(length=0):
while True:
now = datetime.datetime.now()
elapsed = now - start
+ rest = elapsed * ratio + datetime.timedelta(seconds=rest_accum)
time_left = end - now
if length > 0 and time_left.total_seconds() <= 0:
break
ch = inputs.getch_nb(timeout)
if ch == 'q':
+ rest = datetime.timedelta()
+ break
+ elif ch == ' ':
break
if length > 0:
@@ -30,11 +34,12 @@ def timer(length=0):
time_display = elapsed
# see https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
- print("\x1b[2K\r" + inputs.delta_to_HM(time_display), end="", flush=True)
+ print("\x1b[2K\r" + inputs.delta_to_HM(time_display) + "\t" +
+ inputs.delta_to_HM(rest), end="", flush=True)
accum += timeout
if accum >= 1:
accum = 0
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
- return (elapsed, start)
+ return (elapsed.total_seconds(), rest.total_seconds(), start)