From 7dda8d34b5bbfa78a76c84011a5ce7f334f089eb Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Mon, 2 Nov 2015 18:02:54 +0100 Subject: [PATCH] Made terminal.output_progress(...) aware of the terminal width. Instead of clearing the row using the "\b" character on each iteration, the function now passes a carriage return ("\r") instead. Furthermore, the row is now always completely cleared before printing the progress. --- gitinspector/terminal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gitinspector/terminal.py b/gitinspector/terminal.py index 38176df..4d65711 100644 --- a/gitinspector/terminal.py +++ b/gitinspector/terminal.py @@ -148,6 +148,11 @@ def rjust(string, pad): def output_progress(text, pos, length): if sys.stdout.isatty(): - clear_row() - print(text.format(100 * pos / length), end="") + (width, _unused) = get_size() + progress_text = text.format(100 * pos / length) + + if len(progress_text) > width: + progress_text = "...%s" % progress_text[-width+3:] + + print("\r{0}\r{1}".format(" " * width, progress_text), end="") sys.stdout.flush()