17 def spacejoin(*args): |
16 def spacejoin(*args): |
18 return ' '.join(s for s in args if s) |
17 return ' '.join(s for s in args if s) |
19 |
18 |
20 def shouldprint(ui): |
19 def shouldprint(ui): |
21 return not (ui.quiet or ui.plain('progress')) and ( |
20 return not (ui.quiet or ui.plain('progress')) and ( |
22 ui._isatty(sys.stderr) or ui.configbool('progress', 'assume-tty')) |
21 ui._isatty(ui.ferr) or ui.configbool('progress', 'assume-tty')) |
23 |
22 |
24 def fmtremaining(seconds): |
23 def fmtremaining(seconds): |
25 """format a number of remaining seconds in human readable way |
24 """format a number of remaining seconds in human readable way |
26 |
25 |
27 This will properly display seconds, minutes, hours, days if needed""" |
26 This will properly display seconds, minutes, hours, days if needed""" |
156 ' ' * int(abs(amt))) |
155 ' ' * int(abs(amt))) |
157 prog = ''.join(('[', bar , ']')) |
156 prog = ''.join(('[', bar , ']')) |
158 out = spacejoin(head, prog, tail) |
157 out = spacejoin(head, prog, tail) |
159 else: |
158 else: |
160 out = spacejoin(head, tail) |
159 out = spacejoin(head, tail) |
161 sys.stderr.write('\r' + encoding.trim(out, termwidth)) |
160 self.ui.ferr.write('\r' + encoding.trim(out, termwidth)) |
162 self.lasttopic = topic |
161 self.lasttopic = topic |
163 sys.stderr.flush() |
162 self.ui.ferr.flush() |
164 |
163 |
165 def clear(self): |
164 def clear(self): |
166 if not self.printed or not self.lastprint or not shouldprint(self.ui): |
165 if not self.printed or not self.lastprint or not shouldprint(self.ui): |
167 return |
166 return |
168 sys.stderr.write('\r%s\r' % (' ' * self.width())) |
167 self.ui.ferr.write('\r%s\r' % (' ' * self.width())) |
169 if self.printed: |
168 if self.printed: |
170 # force immediate re-paint of progress bar |
169 # force immediate re-paint of progress bar |
171 self.lastprint = 0 |
170 self.lastprint = 0 |
172 |
171 |
173 def complete(self): |
172 def complete(self): |
174 if not shouldprint(self.ui): |
173 if not shouldprint(self.ui): |
175 return |
174 return |
176 if self.ui.configbool('progress', 'clear-complete', default=True): |
175 if self.ui.configbool('progress', 'clear-complete', default=True): |
177 self.clear() |
176 self.clear() |
178 else: |
177 else: |
179 sys.stderr.write('\n') |
178 self.ui.ferr.write('\n') |
180 sys.stderr.flush() |
179 self.ui.ferr.flush() |
181 |
180 |
182 def width(self): |
181 def width(self): |
183 tw = self.ui.termwidth() |
182 tw = self.ui.termwidth() |
184 return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
183 return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
185 |
184 |