aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpux <pux@pux.dom>2020-02-27 20:00:23 +0100
committerpux <pux@pux.dom>2020-02-27 20:00:23 +0100
commitd63e62f9769dbbabfa71366e585ef5a5e41b726d (patch)
tree8b9015eb4545702064aaa00e07d1c2a5752ada9d
parent8858513feca0ca8f1c8e4f08cf76e833c950e5e2 (diff)
downloadtimebomb-d63e62f9769dbbabfa71366e585ef5a5e41b726d.tar.gz
timebomb-d63e62f9769dbbabfa71366e585ef5a5e41b726d.tar.bz2
timebomb-d63e62f9769dbbabfa71366e585ef5a5e41b726d.zip
fix -m 400 or something like that, progress bar size dynamic (terminal width)
-rw-r--r--README.md3
-rw-r--r--timebomb.py30
2 files changed, 24 insertions, 9 deletions
diff --git a/README.md b/README.md
index a31e5f6..ee65050 100644
--- a/README.md
+++ b/README.md
@@ -4,4 +4,5 @@
### TODO
-- [ ] progress bar: dynamic length (depending on terminal width)
+- [x] progress bar: dynamic length (depending on terminal width)
+- [x] fix input like -m 400 -> convert to mins and secs
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