Add ui.progress API
authorMatt Mackall <mpm@selenic.com>
Thu, 16 Jul 2009 14:49:52 -0500
changeset 9153 6adc899c98d0
parent 9152 4017291c4c48
child 9154 47ce7a3a1fb0
Add ui.progress API
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))