summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorhmj6502 <hashim@hmj6502.com>2025-12-19 09:45:00 +0000
committerhmj6502 <hashim@hmj6502.com>2025-12-19 09:45:00 +0000
commit8ad2527392fbe3fc69a1bca4fa093ace69f3289e (patch)
treec9b98f03a02acf78fb6e4fb6af657369c92c1bf0 /main.py
parent392ed614a8f6d10d31812150cffd20f39e91509a (diff)
downloadlock-n-log-8ad2527392fbe3fc69a1bca4fa093ace69f3289e.tar.gz
lock-n-log-8ad2527392fbe3fc69a1bca4fa093ace69f3289e.tar.bz2
lock-n-log-8ad2527392fbe3fc69a1bca4fa093ace69f3289e.zip
move countdown timer to seperate file
Diffstat (limited to 'main.py')
-rw-r--r--main.py30
1 files changed, 2 insertions, 28 deletions
diff --git a/main.py b/main.py
index 93c6a5d..bde6bf8 100644
--- a/main.py
+++ b/main.py
@@ -2,13 +2,10 @@ import pygal
import csv
import time
import datetime
-import datetime
import hashlib
from collections import OrderedDict
-import termios
-import tty
-import sys
import inputs
+import timers
import formatting as f
print("welcome to lock-n-log, the best way to organise and analyse your focus time!")
@@ -33,30 +30,7 @@ if option == 't':
print("timer length (in minutes)? ", end="", flush=True)
timer_length = inputs.get_pos_int()
- time_left = timer_length
- start = datetime.datetime.now()
- end = start + datetime.timedelta(seconds=time_left) # change to mins in final
- accum = 0
- timeout = 1/120 # 120Hz refresh
-
- old_settings = termios.tcgetattr(sys.stdin)
- tty.setcbreak(sys.stdin.fileno())
- while True:
- now = datetime.datetime.now()
- time_left = end - now
- if time_left.total_seconds() <= 0:
- break
-
- ch = inputs.getch_nb(timeout)
- if ch == 'q':
- print("exited early!")
- break
- # see https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
- print("\x1b[2K\r" + inputs.delta_to_HM(time_left), end="", flush=True)
- accum += timeout
- if accum >= 1:
- accum = 0
- termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
+ time_left, start = timers.countdown(timer_length)
print("\nfocus session finished!\nlogging...")
session = OrderedDict()