summaryrefslogtreecommitdiffstats
path: root/progress.py
diff options
context:
space:
mode:
Diffstat (limited to 'progress.py')
-rw-r--r--progress.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/progress.py b/progress.py
index 7d4f71f1..1eff04ac 100644
--- a/progress.py
+++ b/progress.py
@@ -21,6 +21,11 @@ from repo_trace import IsTrace
21 21
22_NOT_TTY = not os.isatty(2) 22_NOT_TTY = not os.isatty(2)
23 23
24# This will erase all content in the current line (wherever the cursor is).
25# It does not move the cursor, so this is usually followed by \r to move to
26# column 0.
27CSI_ERASE_LINE = '\x1b[2K'
28
24class Progress(object): 29class Progress(object):
25 def __init__(self, title, total=0, units='', print_newline=False, 30 def __init__(self, title, total=0, units='', print_newline=False,
26 always_print_percentage=False): 31 always_print_percentage=False):
@@ -47,7 +52,8 @@ class Progress(object):
47 return 52 return
48 53
49 if self._total <= 0: 54 if self._total <= 0:
50 sys.stderr.write('\r%s: %d, ' % ( 55 sys.stderr.write('%s\r%s: %d,' % (
56 CSI_ERASE_LINE,
51 self._title, 57 self._title,
52 self._done)) 58 self._done))
53 sys.stderr.flush() 59 sys.stderr.flush()
@@ -56,7 +62,8 @@ class Progress(object):
56 62
57 if self._lastp != p or self._always_print_percentage: 63 if self._lastp != p or self._always_print_percentage:
58 self._lastp = p 64 self._lastp = p
59 sys.stderr.write('\r%s: %3d%% (%d%s/%d%s)%s' % ( 65 sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s' % (
66 CSI_ERASE_LINE,
60 self._title, 67 self._title,
61 p, 68 p,
62 self._done, self._units, 69 self._done, self._units,
@@ -69,13 +76,15 @@ class Progress(object):
69 return 76 return
70 77
71 if self._total <= 0: 78 if self._total <= 0:
72 sys.stderr.write('\r%s: %d, done. \n' % ( 79 sys.stderr.write('%s\r%s: %d, done.\n' % (
80 CSI_ERASE_LINE,
73 self._title, 81 self._title,
74 self._done)) 82 self._done))
75 sys.stderr.flush() 83 sys.stderr.flush()
76 else: 84 else:
77 p = (100 * self._done) / self._total 85 p = (100 * self._done) / self._total
78 sys.stderr.write('\r%s: %3d%% (%d%s/%d%s), done. \n' % ( 86 sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s), done.\n' % (
87 CSI_ERASE_LINE,
79 self._title, 88 self._title,
80 p, 89 p,
81 self._done, self._units, 90 self._done, self._units,