[PATCH 4 of 8] progress: slightly nicer handling of nested progress topics
Augie Fackler
durin42 at gmail.com
Thu Dec 9 23:41:04 UTC 2010
# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1287459980 18000
# Node ID 50766f487403088037b03f8d183a2bb30f03c1dd
# Parent 81e2508690be5edc7a418472f891c125ed33907d
progress: slightly nicer handling of nested progress topics
Previously we'd declare "complete" after an inner progress topic
completed and erase the progress bar. Now we print the state of the
enclosing progress topic as it was last recorded.
diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -62,6 +62,7 @@
def resetstate(self):
self.topics = []
+ self.topicstates = {}
self.pendingtopics = {}
self.printed = False
self.lastprint = time.time() + float(self.ui.config(
@@ -76,8 +77,12 @@
def show(self, topic, pos, item, unit, total):
if not shouldprint(self.ui):
return
+ if self.printed == (topic, pos, item, unit, total):
+ # don't double-print progress information, otherwise
+ # possible in the case of unwinding the topic stack
+ return
termwidth = self.width()
- self.printed = True
+ self.printed = (topic, pos, item, unit, total)
head = ''
needprogress = False
tail = ''
@@ -164,9 +169,11 @@
def progress(self, topic, pos, item='', unit='', total=None):
if pos is None:
self.pendingtopics.pop(topic, None)
- if self.topics and self.topics[-1] == topic and self.printed:
+ if self.topics and self.topics[0] == topic and self.printed:
self.complete()
self.resetstate()
+ if topic in self.topics:
+ self.topics = self.topics[:self.topics.index(topic)]
else:
if self.topics:
if topic in self.pendingtopics:
@@ -179,11 +186,12 @@
if topic not in self.topics:
self.pendingtopics[topic] = 0
self.topics.append(topic)
- now = time.time()
- if (now - self.lastprint >= self.refresh
- and topic == self.topics[-1]):
- self.lastprint = now
- self.show(topic, pos, item, unit, total)
+ self.topicstates[topic] = pos, item, unit, total
+ now = time.time()
+ if now - self.lastprint >= self.refresh and self.topics:
+ self.lastprint = now
+ curtopic = self.topics[-1]
+ self.show(curtopic, *self.topicstates[curtopic])
def uisetup(ui):
class progressui(ui.__class__):
More information about the Mercurial-devel
mailing list