changeset 13147:082f5be788d9

progress: only show time estimate when progress format contains 'estimate'
author Augie Fackler <durin42@gmail.com>
date Wed, 15 Dec 2010 10:22:06 -0600
parents 43575c67add3
children ab5fcc473fd1
files hgext/progress.py
diffstat 1 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/progress.py	Wed Dec 15 10:20:36 2010 -0600
+++ b/hgext/progress.py	Wed Dec 15 10:22:06 2010 -0600
@@ -36,10 +36,11 @@
   assume-tty = False # if true, ALWAYS show a progress bar, unless
                      # disable is given
 
-Valid entries for the format field are topic, bar, number, unit, and
-item. item defaults to the last 20 characters of the item, but this
-can be changed by adding either ``-<num>`` which would take the last
-num characters, or ``+<num>`` for the first num characters.
+Valid entries for the format field are topic, bar, number, unit,
+estimate, and item. item defaults to the last 20 characters of the
+item, but this can be changed by adding either ``-<num>`` which would
+take the last num characters, or ``+<num>`` for the first num
+characters.
 """
 
 import sys
@@ -128,6 +129,8 @@
                 needprogress = True
             elif indicator == 'unit' and unit:
                 add = unit
+            elif indicator == 'estimate':
+                add = self.estimate(topic, pos, total, now)
             if not needprogress:
                 head = spacejoin(head, add)
             else:
@@ -140,17 +143,6 @@
                 used += len(tail) + 1
             progwidth = termwidth - used - 3
             if total and pos <= total:
-                initial = self.startvals[topic]
-                target = total - initial
-                delta = pos - initial
-                if delta > 0:
-                    elapsed = now - self.starttimes[topic]
-                    if elapsed > float(
-                        self.ui.config('progress', 'estimate', default=2)):
-                        seconds = (elapsed * (target - delta)) // delta + 1
-                        remaining = fmtremaining(seconds)
-                        progwidth -= len(remaining) + 1
-                        tail = spacejoin(tail, remaining)
                 amt = pos * progwidth // total
                 bar = '=' * (amt - 1)
                 if amt > 0:
@@ -190,6 +182,18 @@
         tw = self.ui.termwidth()
         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
 
+    def estimate(self, topic, pos, total, now):
+        initialpos = self.startvals[topic]
+        target = total - initialpos
+        delta = pos - initialpos
+        if delta > 0:
+            elapsed = now - self.starttimes[topic]
+            if elapsed > float(
+                self.ui.config('progress', 'estimate', default=2)):
+                seconds = (elapsed * (target - delta)) // delta + 1
+                return fmtremaining(seconds)
+        return ''
+
     def progress(self, topic, pos, item='', unit='', total=None):
         now = time.time()
         if pos is None: