Show More
@@ -45,6 +45,7 b' num characters, or ``+<num>`` for the fi' | |||
|
45 | 45 | import sys |
|
46 | 46 | import time |
|
47 | 47 | |
|
48 | from mercurial.i18n import _ | |
|
48 | 49 | from mercurial import util |
|
49 | 50 | |
|
50 | 51 | def spacejoin(*args): |
@@ -62,6 +63,8 b' class progbar(object):' | |||
|
62 | 63 | def resetstate(self): |
|
63 | 64 | self.topics = [] |
|
64 | 65 | self.topicstates = {} |
|
66 | self.starttimes = {} | |
|
67 | self.startvals = {} | |
|
65 | 68 | self.printed = False |
|
66 | 69 | self.lastprint = time.time() + float(self.ui.config( |
|
67 | 70 | 'progress', 'delay', default=3)) |
@@ -72,7 +75,7 b' class progbar(object):' | |||
|
72 | 75 | 'progress', 'format', |
|
73 | 76 | default=['topic', 'bar', 'number']) |
|
74 | 77 | |
|
75 | def show(self, topic, pos, item, unit, total): | |
|
78 | def show(self, now, topic, pos, item, unit, total): | |
|
76 | 79 | if not shouldprint(self.ui): |
|
77 | 80 | return |
|
78 | 81 | termwidth = self.width() |
@@ -121,6 +124,26 b' class progbar(object):' | |||
|
121 | 124 | used += len(tail) + 1 |
|
122 | 125 | progwidth = termwidth - used - 3 |
|
123 | 126 | if total and pos <= total: |
|
127 | initial = self.startvals[topic] | |
|
128 | target = total - initial | |
|
129 | delta = pos - initial | |
|
130 | if delta > 0: | |
|
131 | elapsed = now - self.starttimes[topic] | |
|
132 | if elapsed > float( | |
|
133 | self.ui.config('progress', 'estimate', default=2)): | |
|
134 | seconds = (elapsed * (target - delta)) // delta + 1 | |
|
135 | minutes = seconds // 60 | |
|
136 | if minutes < 10: | |
|
137 | seconds -= minutes * 60 | |
|
138 | remaining = _("%dm%02ds") % (minutes, seconds) | |
|
139 | else: | |
|
140 | # we're going to ignore seconds in this case | |
|
141 | minutes += 1 | |
|
142 | hours = minutes // 60 | |
|
143 | minutes -= hours * 60 | |
|
144 | remaining = _("%dh%02dm") % (hours, minutes) | |
|
145 | progwidth -= len(remaining) + 1 | |
|
146 | tail = spacejoin(tail, remaining) | |
|
124 | 147 | amt = pos * progwidth // total |
|
125 | 148 | bar = '=' * (amt - 1) |
|
126 | 149 | if amt > 0: |
@@ -161,7 +184,10 b' class progbar(object):' | |||
|
161 | 184 | return min(int(self.ui.config('progress', 'width', default=tw)), tw) |
|
162 | 185 | |
|
163 | 186 | def progress(self, topic, pos, item='', unit='', total=None): |
|
187 | now = time.time() | |
|
164 | 188 | if pos is None: |
|
189 | self.starttimes.pop(topic, None) | |
|
190 | self.startvals.pop(topic, None) | |
|
165 | 191 | self.topicstates.pop(topic, None) |
|
166 | 192 | # reset the progress bar if this is the outermost topic |
|
167 | 193 | if self.topics and self.topics[0] == topic and self.printed: |
@@ -173,13 +199,14 b' class progbar(object):' | |||
|
173 | 199 | self.topics = self.topics[:self.topics.index(topic)] |
|
174 | 200 | else: |
|
175 | 201 | if topic not in self.topics: |
|
202 | self.starttimes[topic] = now | |
|
203 | self.startvals[topic] = pos | |
|
176 | 204 | self.topics.append(topic) |
|
177 | now = time.time() | |
|
178 | 205 | self.topicstates[topic] = pos, item, unit, total |
|
179 | 206 | if now - self.lastprint >= self.refresh and self.topics: |
|
180 | 207 | self.lastprint = now |
|
181 | 208 | current = self.topics[-1] |
|
182 |
self.show( |
|
|
209 | self.show(now, topic, *self.topicstates[topic]) | |
|
183 | 210 | |
|
184 | 211 | def uisetup(ui): |
|
185 | 212 | class progressui(ui.__class__): |
General Comments 0
You need to be logged in to leave comments.
Login now