Show More
@@ -165,10 +165,10 b' class progbar(object):' | |||
|
165 | 165 | self.show(topic, pos, item, unit, total) |
|
166 | 166 | return orig(topic, pos, item=item, unit=unit, total=total) |
|
167 | 167 | |
|
168 | def write(self, orig, *args): | |
|
168 | def write(self, orig, *args, **opts): | |
|
169 | 169 | if self.printed: |
|
170 | 170 | self.clear() |
|
171 | return orig(*args) | |
|
171 | return orig(*args, **opts) | |
|
172 | 172 | |
|
173 | 173 | sharedprog = None |
|
174 | 174 |
@@ -239,17 +239,42 b' class ui(object):' | |||
|
239 | 239 | def pushbuffer(self): |
|
240 | 240 | self._buffers.append([]) |
|
241 | 241 | |
|
242 | def popbuffer(self): | |
|
242 | def popbuffer(self, labeled=False): | |
|
243 | '''pop the last buffer and return the buffered output | |
|
244 | ||
|
245 | If labeled is True, any labels associated with buffered | |
|
246 | output will be handled. By default, this has no effect | |
|
247 | on the output returned, but extensions and GUI tools may | |
|
248 | handle this argument and returned styled output. If output | |
|
249 | is being buffered so it can be captured and parsed or | |
|
250 | processed, labeled should not be set to True. | |
|
251 | ''' | |
|
243 | 252 | return "".join(self._buffers.pop()) |
|
244 | 253 | |
|
245 | def write(self, *args): | |
|
254 | def write(self, *args, **opts): | |
|
255 | '''write args to output | |
|
256 | ||
|
257 | By default, this method simply writes to the buffer or stdout, | |
|
258 | but extensions or GUI tools may override this method, | |
|
259 | write_err(), popbuffer(), and label() to style output from | |
|
260 | various parts of hg. | |
|
261 | ||
|
262 | An optional keyword argument, "label", can be passed in. | |
|
263 | This should be a string containing label names separated by | |
|
264 | space. Label names take the form of "topic.type". For example, | |
|
265 | ui.debug() issues a label of "ui.debug". | |
|
266 | ||
|
267 | When labeling output for a specific command, a label of | |
|
268 | "cmdname.type" is recommended. For example, status issues | |
|
269 | a label of "status.modified" for modified files. | |
|
270 | ''' | |
|
246 | 271 | if self._buffers: |
|
247 | 272 | self._buffers[-1].extend([str(a) for a in args]) |
|
248 | 273 | else: |
|
249 | 274 | for a in args: |
|
250 | 275 | sys.stdout.write(str(a)) |
|
251 | 276 | |
|
252 | def write_err(self, *args): | |
|
277 | def write_err(self, *args, **opts): | |
|
253 | 278 | try: |
|
254 | 279 | if not getattr(sys.stdout, 'closed', False): |
|
255 | 280 | sys.stdout.flush() |
@@ -335,17 +360,37 b' class ui(object):' | |||
|
335 | 360 | return getpass.getpass(prompt or _('password: ')) |
|
336 | 361 | except EOFError: |
|
337 | 362 | raise util.Abort(_('response expected')) |
|
338 | def status(self, *msg): | |
|
363 | def status(self, *msg, **opts): | |
|
364 | '''write status message to output (if ui.quiet is False) | |
|
365 | ||
|
366 | This adds an output label of "ui.status". | |
|
367 | ''' | |
|
339 | 368 | if not self.quiet: |
|
340 | self.write(*msg) | |
|
341 | def warn(self, *msg): | |
|
342 | self.write_err(*msg) | |
|
343 | def note(self, *msg): | |
|
369 | opts['label'] = opts.get('label', '') + ' ui.status' | |
|
370 | self.write(*msg, **opts) | |
|
371 | def warn(self, *msg, **opts): | |
|
372 | '''write warning message to output (stderr) | |
|
373 | ||
|
374 | This adds an output label of "ui.warning". | |
|
375 | ''' | |
|
376 | opts['label'] = opts.get('label', '') + ' ui.warning' | |
|
377 | self.write_err(*msg, **opts) | |
|
378 | def note(self, *msg, **opts): | |
|
379 | '''write note to output (if ui.verbose is True) | |
|
380 | ||
|
381 | This adds an output label of "ui.note". | |
|
382 | ''' | |
|
344 | 383 | if self.verbose: |
|
345 | self.write(*msg) | |
|
346 | def debug(self, *msg): | |
|
384 | opts['label'] = opts.get('label', '') + ' ui.note' | |
|
385 | self.write(*msg, **opts) | |
|
386 | def debug(self, *msg, **opts): | |
|
387 | '''write debug message to output (if ui.debugflag is True) | |
|
388 | ||
|
389 | This adds an output label of "ui.debug". | |
|
390 | ''' | |
|
347 | 391 | if self.debugflag: |
|
348 | self.write(*msg) | |
|
392 | opts['label'] = opts.get('label', '') + ' ui.debug' | |
|
393 | self.write(*msg, **opts) | |
|
349 | 394 | def edit(self, text, user): |
|
350 | 395 | (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt", |
|
351 | 396 | text=True) |
@@ -417,3 +462,15 b' class ui(object):' | |||
|
417 | 462 | % (topic, item, pos, total, unit, pct)) |
|
418 | 463 | else: |
|
419 | 464 | self.debug('%s:%s %s%s\n' % (topic, item, pos, unit)) |
|
465 | ||
|
466 | def label(self, msg, label): | |
|
467 | '''style msg based on supplied label | |
|
468 | ||
|
469 | Like ui.write(), this just returns msg unchanged, but extensions | |
|
470 | and GUI tools can override it to allow styling output without | |
|
471 | writing it. | |
|
472 | ||
|
473 | ui.write(s, 'label') is equivalent to | |
|
474 | ui.write(ui.label(s, 'label')). | |
|
475 | ''' | |
|
476 | return msg |
General Comments 0
You need to be logged in to leave comments.
Login now