# HG changeset patch # User Matt Mackall # Date 1247773792 18000 # Node ID 6adc899c98d00cf6f70d2261e0ce8b7a64d21c5f # Parent 4017291c4c4853a5dcdb133f269840153595b6c6 Add ui.progress API diff -r 4017291c4c48 -r 6adc899c98d0 mercurial/ui.py --- a/mercurial/ui.py Thu Jul 16 10:41:19 2009 -0400 +++ b/mercurial/ui.py Thu Jul 16 14:49:52 2009 -0500 @@ -349,3 +349,33 @@ self.config("ui", "editor") or os.environ.get("VISUAL") or os.environ.get("EDITOR", "vi")) + + def progress(self, topic, pos, item="", unit="", total=None): + '''show a progress message + + With stock hg, this is simply a debug message that is hidden + by default, but with extensions or GUI tools it may be + visible. 'topic' is the current operation, 'item' is a + non-numeric marker of the current position (ie the currently + in-process file), 'pos' is the current numeric position (ie + revision, bytes, etc.), units is a corresponding unit label, + and total is the highest expected pos. + + Multiple nested topics may be active at a time. All topics + should be marked closed by setting pos to None at termination. + ''' + + if pos == None or not self.debugflag: + return + + if units: + units = ' ' + units + if item: + item = ' ' + item + + if total: + pct = 100.0 * pos / total + ui.debug('%s:%s %s/%s%s (%4.2g%%)\n' + % (topic, item, pos, total, units, pct)) + else: + ui.debug('%s:%s %s%s\n' % (topic, item, pos, units))