hgext/progress.py
changeset 13130 f139f34ba330
parent 12689 c52c629ce19e
child 13131 c9ae7e096994
equal deleted inserted replaced
13129:873c032c81b5 13130:f139f34ba330
    59         self.ui = ui
    59         self.ui = ui
    60         self.resetstate()
    60         self.resetstate()
    61 
    61 
    62     def resetstate(self):
    62     def resetstate(self):
    63         self.topics = []
    63         self.topics = []
       
    64         self.topicstates = {}
    64         self.printed = False
    65         self.printed = False
    65         self.lastprint = time.time() + float(self.ui.config(
    66         self.lastprint = time.time() + float(self.ui.config(
    66             'progress', 'delay', default=3))
    67             'progress', 'delay', default=3))
    67         self.indetcount = 0
    68         self.indetcount = 0
    68         self.refresh = float(self.ui.config(
    69         self.refresh = float(self.ui.config(
   159         tw = self.ui.termwidth()
   160         tw = self.ui.termwidth()
   160         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
   161         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
   161 
   162 
   162     def progress(self, topic, pos, item='', unit='', total=None):
   163     def progress(self, topic, pos, item='', unit='', total=None):
   163         if pos is None:
   164         if pos is None:
   164             if self.topics and self.topics[-1] == topic and self.printed:
   165             self.topicstates.pop(topic, None)
       
   166             # reset the progress bar if this is the outermost topic
       
   167             if self.topics and self.topics[0] == topic and self.printed:
   165                 self.complete()
   168                 self.complete()
   166                 self.resetstate()
   169                 self.resetstate()
       
   170             # truncate the list of topics assuming all topics within
       
   171             # this one are also closed
       
   172             if topic in self.topics:
       
   173               self.topics = self.topics[:self.topics.index(topic)]
   167         else:
   174         else:
   168             if topic not in self.topics:
   175             if topic not in self.topics:
   169                 self.topics.append(topic)
   176                 self.topics.append(topic)
   170             now = time.time()
   177             now = time.time()
   171             if (now - self.lastprint >= self.refresh
   178             self.topicstates[topic] = pos, item, unit, total
   172                 and topic == self.topics[-1]):
   179             if now - self.lastprint >= self.refresh and self.topics:
   173                 self.lastprint = now
   180                 self.lastprint = now
   174                 self.show(topic, pos, item, unit, total)
   181                 current = self.topics[-1]
       
   182                 self.show(current, *self.topicstates[current])
   175 
   183 
   176 def uisetup(ui):
   184 def uisetup(ui):
   177     class progressui(ui.__class__):
   185     class progressui(ui.__class__):
   178         _progbar = None
   186         _progbar = None
   179 
   187