diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-11-29 13:53:03 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-11-29 13:53:03 +0100 |
commit | 6957094c427f129b651651fd10b0000827cd2403 (patch) | |
tree | 9d46f419ee0716163c0090c6210d58b840898639 /fb.py | |
parent | 7c60034b9823d3b751900c5360c629b44d5572b7 (diff) |
Use ANSI code to clear output line
\033[K clears the line starting from the cursor position.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'fb.py')
-rwxr-xr-x | fb.py | 14 |
1 files changed, 3 insertions, 11 deletions
@@ -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"] |