changeset 9153:6adc899c98d0

Add ui.progress API
author Matt Mackall <mpm@selenic.com>
date Thu, 16 Jul 2009 14:49:52 -0500
parents 4017291c4c48
children 47ce7a3a1fb0
files mercurial/ui.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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))