Mercurial > public > mercurial-scm > hg
comparison mercurial/progress.py @ 32048:c3ef33fd0058
progress: extract stubs to restart ferr.flush() and .write() on EINTR
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 13 Apr 2017 22:27:25 +0900 |
parents | cb1ea3cc44b5 |
children | ed42e00a5c4e |
comparison
equal
deleted
inserted
replaced
32047:458f7294dfee | 32048:c3ef33fd0058 |
---|---|
155 ' ' * int(abs(amt))) | 155 ' ' * int(abs(amt))) |
156 prog = ''.join(('[', bar , ']')) | 156 prog = ''.join(('[', bar , ']')) |
157 out = spacejoin(head, prog, tail) | 157 out = spacejoin(head, prog, tail) |
158 else: | 158 else: |
159 out = spacejoin(head, tail) | 159 out = spacejoin(head, tail) |
160 self.ui.ferr.write('\r' + encoding.trim(out, termwidth)) | 160 self._writeerr('\r' + encoding.trim(out, termwidth)) |
161 self.lasttopic = topic | 161 self.lasttopic = topic |
162 self.ui.ferr.flush() | 162 self._flusherr() |
163 | 163 |
164 def clear(self): | 164 def clear(self): |
165 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): |
166 return | 166 return |
167 self.ui.ferr.write('\r%s\r' % (' ' * self.width())) | 167 self._writeerr('\r%s\r' % (' ' * self.width())) |
168 if self.printed: | 168 if self.printed: |
169 # force immediate re-paint of progress bar | 169 # force immediate re-paint of progress bar |
170 self.lastprint = 0 | 170 self.lastprint = 0 |
171 | 171 |
172 def complete(self): | 172 def complete(self): |
173 if not shouldprint(self.ui): | 173 if not shouldprint(self.ui): |
174 return | 174 return |
175 if self.ui.configbool('progress', 'clear-complete', default=True): | 175 if self.ui.configbool('progress', 'clear-complete', default=True): |
176 self.clear() | 176 self.clear() |
177 else: | 177 else: |
178 self.ui.ferr.write('\n') | 178 self._writeerr('\n') |
179 self._flusherr() | |
180 | |
181 def _flusherr(self): | |
179 self.ui.ferr.flush() | 182 self.ui.ferr.flush() |
183 | |
184 def _writeerr(self, msg): | |
185 self.ui.ferr.write(msg) | |
180 | 186 |
181 def width(self): | 187 def width(self): |
182 tw = self.ui.termwidth() | 188 tw = self.ui.termwidth() |
183 return min(int(self.ui.config('progress', 'width', default=tw)), tw) | 189 return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
184 | 190 |