##// END OF EJS Templates
progress: only show time estimate when progress format contains 'estimate'
Augie Fackler -
r13147:082f5be7 default
parent child Browse files
Show More
@@ -36,10 +36,11 b' The following settings are available::'
36 assume-tty = False # if true, ALWAYS show a progress bar, unless
36 assume-tty = False # if true, ALWAYS show a progress bar, unless
37 # disable is given
37 # disable is given
38
38
39 Valid entries for the format field are topic, bar, number, unit, and
39 Valid entries for the format field are topic, bar, number, unit,
40 item. item defaults to the last 20 characters of the item, but this
40 estimate, and item. item defaults to the last 20 characters of the
41 can be changed by adding either ``-<num>`` which would take the last
41 item, but this can be changed by adding either ``-<num>`` which would
42 num characters, or ``+<num>`` for the first num characters.
42 take the last num characters, or ``+<num>`` for the first num
43 characters.
43 """
44 """
44
45
45 import sys
46 import sys
@@ -128,6 +129,8 b' class progbar(object):'
128 needprogress = True
129 needprogress = True
129 elif indicator == 'unit' and unit:
130 elif indicator == 'unit' and unit:
130 add = unit
131 add = unit
132 elif indicator == 'estimate':
133 add = self.estimate(topic, pos, total, now)
131 if not needprogress:
134 if not needprogress:
132 head = spacejoin(head, add)
135 head = spacejoin(head, add)
133 else:
136 else:
@@ -140,17 +143,6 b' class progbar(object):'
140 used += len(tail) + 1
143 used += len(tail) + 1
141 progwidth = termwidth - used - 3
144 progwidth = termwidth - used - 3
142 if total and pos <= total:
145 if total and pos <= total:
143 initial = self.startvals[topic]
144 target = total - initial
145 delta = pos - initial
146 if delta > 0:
147 elapsed = now - self.starttimes[topic]
148 if elapsed > float(
149 self.ui.config('progress', 'estimate', default=2)):
150 seconds = (elapsed * (target - delta)) // delta + 1
151 remaining = fmtremaining(seconds)
152 progwidth -= len(remaining) + 1
153 tail = spacejoin(tail, remaining)
154 amt = pos * progwidth // total
146 amt = pos * progwidth // total
155 bar = '=' * (amt - 1)
147 bar = '=' * (amt - 1)
156 if amt > 0:
148 if amt > 0:
@@ -190,6 +182,18 b' class progbar(object):'
190 tw = self.ui.termwidth()
182 tw = self.ui.termwidth()
191 return min(int(self.ui.config('progress', 'width', default=tw)), tw)
183 return min(int(self.ui.config('progress', 'width', default=tw)), tw)
192
184
185 def estimate(self, topic, pos, total, now):
186 initialpos = self.startvals[topic]
187 target = total - initialpos
188 delta = pos - initialpos
189 if delta > 0:
190 elapsed = now - self.starttimes[topic]
191 if elapsed > float(
192 self.ui.config('progress', 'estimate', default=2)):
193 seconds = (elapsed * (target - delta)) // delta + 1
194 return fmtremaining(seconds)
195 return ''
196
193 def progress(self, topic, pos, item='', unit='', total=None):
197 def progress(self, topic, pos, item='', unit='', total=None):
194 now = time.time()
198 now = time.time()
195 if pos is None:
199 if pos is None:
General Comments 0
You need to be logged in to leave comments. Login now