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.
This commit is contained in:
Adam Waldenberg 2015-11-02 18:02:54 +01:00
parent d5106a7302
commit 7dda8d34b5
1 changed files with 7 additions and 2 deletions

View File

@ -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()