From f663ff01e7e4181e36b33bb5caf35074bbaf6d51 Mon Sep 17 00:00:00 2001 From: eli fessler Date: Wed, 28 Sep 2022 11:21:14 -1000 Subject: [PATCH] add shutil instad of os libary for get_terminal_size()& code merges --- s3s.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/s3s.py b/s3s.py index 13ff6c7..72736b0 100755 --- a/s3s.py +++ b/s3s.py @@ -1004,17 +1004,23 @@ def monitor_battles(which, secs, isblackout, istestrun): print("Bye!") class SquidProgress: - def __init__(self): - self.count = 0 + '''Display animation while waiting.''' - def __call__(self): - lineend = shutil.get_terminal_size()[0] - 4 - ika = '>=> ' if self.count % 2 == 0 else '===>' - sys.stdout.write(f"\r{' '*self.count}{ika}{' '*(lineend - self.count)}") - sys.stdout.flush() - self.count += 1 - if self.count > lineend: - self.count = 0 + def __init__(self): + self.count = 0 + + def __call__(self): + lineend = shutil.get_terminal_size()[0] - 5 # 5 = ('>=> ' or '===>') + blank 1 + ika = '>=> ' if self.count % 2 == 0 else '===>' + sys.stdout.write(f"\r{' '*self.count}{ika}{' '*(lineend - self.count)}") + sys.stdout.flush() + self.count += 1 + if self.count > lineend: + self.count = 0 + + def __del__(self): + sys.stdout.write(f"\r{' '*(os.get_terminal_size()[0] - 1)}\r") + sys.stdout.flush() def main(): '''Main process, including I/O and setup.'''