summaryrefslogtreecommitdiffstats
path: root/progress.py
diff options
context:
space:
mode:
Diffstat (limited to 'progress.py')
-rw-r--r--progress.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/progress.py b/progress.py
index 43c7ad21..f9ac53a1 100644
--- a/progress.py
+++ b/progress.py
@@ -24,6 +24,11 @@ _NOT_TTY = not os.isatty(2)
24# column 0. 24# column 0.
25CSI_ERASE_LINE = '\x1b[2K' 25CSI_ERASE_LINE = '\x1b[2K'
26 26
27# This will erase all content in the current line after the cursor. This is
28# useful for partial updates & progress messages as the terminal can display
29# it better.
30CSI_ERASE_LINE_AFTER = '\x1b[K'
31
27 32
28def duration_str(total): 33def duration_str(total):
29 """A less noisy timedelta.__str__. 34 """A less noisy timedelta.__str__.
@@ -85,10 +90,10 @@ class Progress(object):
85 return 90 return
86 91
87 if self._total <= 0: 92 if self._total <= 0:
88 sys.stderr.write('%s\r%s: %d,' % ( 93 sys.stderr.write('\r%s: %d,%s' % (
89 CSI_ERASE_LINE,
90 self._title, 94 self._title,
91 self._done)) 95 self._done,
96 CSI_ERASE_LINE_AFTER))
92 sys.stderr.flush() 97 sys.stderr.flush()
93 else: 98 else:
94 p = (100 * self._done) / self._total 99 p = (100 * self._done) / self._total
@@ -96,14 +101,14 @@ class Progress(object):
96 jobs = '[%d job%s] ' % (self._active, 's' if self._active > 1 else '') 101 jobs = '[%d job%s] ' % (self._active, 's' if self._active > 1 else '')
97 else: 102 else:
98 jobs = '' 103 jobs = ''
99 sys.stderr.write('%s\r%s: %2d%% %s(%d%s/%d%s)%s%s%s' % ( 104 sys.stderr.write('\r%s: %2d%% %s(%d%s/%d%s)%s%s%s%s' % (
100 CSI_ERASE_LINE,
101 self._title, 105 self._title,
102 p, 106 p,
103 jobs, 107 jobs,
104 self._done, self._units, 108 self._done, self._units,
105 self._total, self._units, 109 self._total, self._units,
106 ' ' if msg else '', msg, 110 ' ' if msg else '', msg,
111 CSI_ERASE_LINE_AFTER,
107 '\n' if self._print_newline else '')) 112 '\n' if self._print_newline else ''))
108 sys.stderr.flush() 113 sys.stderr.flush()
109 114
@@ -113,19 +118,19 @@ class Progress(object):
113 118
114 duration = duration_str(time() - self._start) 119 duration = duration_str(time() - self._start)
115 if self._total <= 0: 120 if self._total <= 0:
116 sys.stderr.write('%s\r%s: %d, done in %s\n' % ( 121 sys.stderr.write('\r%s: %d, done in %s%s\n' % (
117 CSI_ERASE_LINE,
118 self._title, 122 self._title,
119 self._done, 123 self._done,
120 duration)) 124 duration,
125 CSI_ERASE_LINE_AFTER))
121 sys.stderr.flush() 126 sys.stderr.flush()
122 else: 127 else:
123 p = (100 * self._done) / self._total 128 p = (100 * self._done) / self._total
124 sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s), done in %s\n' % ( 129 sys.stderr.write('\r%s: %3d%% (%d%s/%d%s), done in %s%s\n' % (
125 CSI_ERASE_LINE,
126 self._title, 130 self._title,
127 p, 131 p,
128 self._done, self._units, 132 self._done, self._units,
129 self._total, self._units, 133 self._total, self._units,
130 duration)) 134 duration,
135 CSI_ERASE_LINE_AFTER))
131 sys.stderr.flush() 136 sys.stderr.flush()