From 6957094c427f129b651651fd10b0000827cd2403 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 29 Nov 2015 13:53:03 +0100 Subject: Use ANSI code to clear output line \033[K clears the line starting from the cursor position. Signed-off-by: Florian Pritz --- fb.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/fb.py b/fb.py index a27ed76..6d1c2aa 100755 --- a/fb.py +++ b/fb.py @@ -222,7 +222,6 @@ class ProgressBar: samplecount = 20 self.progressData = { "lastUpdateTime": time.time(), - "lastLineLength": 0, "ullast": 0, "ulGlobalTotal": 0, "ulGlobal": 0, @@ -253,7 +252,7 @@ class ProgressBar: # upload complete, clean up if data["ulGlobal"] >= data["ulGlobalTotal"]: - sys.stderr.write("%s\r" % (" " * (data["lastLineLength"] + 1))) + sys.stderr.write("\r\033[K") return 0 if ulnow == 0: @@ -289,19 +288,12 @@ class ProgressBar: timeRemaining = (data['ulGlobalTotal'] - data['ulGlobal']) / ulspeed eta = self.format_time(timeRemaining) - output = "\r{}/s uploaded: {:.1f}% = {}; ETA: {}".format( + sys.stderr.write("\r{}/s uploaded: {:.1f}% = {}; ETA: {}\033[K".format( self.format_bytes(ulspeed), data['ulGlobal'] * 100 / data['ulGlobalTotal'], self.format_bytes(data['ulGlobal']), str(eta) - ) - - outputlen = len(output) - if data["lastLineLength"] > outputlen: - output += " " * (data["lastLineLength"] - outputlen) - sys.stderr.write(output) - - data["lastLineLength"] = outputlen + )) def format_bytes(self, bytes): suffix = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] -- cgit v1.2.3-24-g4f1b