aboutsummaryrefslogtreecommitdiff
path: root/timebomb.py
diff options
context:
space:
mode:
Diffstat (limited to 'timebomb.py')
-rw-r--r--timebomb.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/timebomb.py b/timebomb.py
index 9cb8496..c3229ce 100644
--- a/timebomb.py
+++ b/timebomb.py
@@ -9,6 +9,7 @@ from tkinter import messagebox
from tkinter import Canvas
import argparse
import time
+import shutil
root = Tk()
@@ -59,18 +60,31 @@ def main():
message(m=time_m, s=time_s)
def sleep(m, s):
+ time_sum_s = - (m * 60) + s
+ time_m, time_s = divmod(time_sum_s, 60)
+
print('Start: ' + time.ctime())
- print('Sleeping for: ' + str(m) \
- + ' mins and ' + str(s) + ' seconds')
+ print('Sleeping for: ' + str(time_m) \
+ + ' mins and ' + str(time_s) + ' seconds')
+
+ for x in range(time_sum_s):
+ # because dynamic resizing this needs to be here
+ cols, rows = shutil.get_terminal_size(fallback=(80, 24))
- sleep_time_s = s + (m*60)
- pbar_len = 40
- for x in range(sleep_time_s):
pr_m, pr_s = divmod(x, 60)
- print(' {:02d}:{:02d} '.format(pr_m, pr_s), end='')
- progress = int(x/(sleep_time_s-1) * pbar_len)
+ left = ' {:02d}:{:02d} '.format(pr_m, pr_s)
+ right = ' {:02d}:{:02d} '.format(time_m, time_s)
+
+ pbar_len = cols - len(left) - len(right)
+ if pbar_len < 20:
+ pbar_len = 20
+
+ progress = int(x/(time_sum_s-1) * pbar_len)
+
+ print(left, end='')
print('#' * progress + '_' * int(pbar_len-progress), end='')
- print(' {:02d}:{:02d} '.format(m, s), end='\r')
+ print(right, end='\r')
+
time.sleep(1)
if __name__ == '__main__':
in each repos: see "about"-tab (if existing) for more details / README.
mailto contact at omeckman dot net
all timestamps in UTC (German winter time: UTC+01:00, summer time: UTC+02:00)
dark theme is a modded version of: https://gist.github.com/Yoplitein/f4b671a2ec70c9e743fa