hgext/progress.py
changeset 10439 509f4ed56509
parent 10434 ad104a786d35
child 10441 dc0d1ca2d378
equal deleted inserted replaced
10438:e6dc44147234 10439:509f4ed56509
   138         sys.stdout.flush()
   138         sys.stdout.flush()
   139 
   139 
   140     def clear(self):
   140     def clear(self):
   141         sys.stdout.write('\r%s\r' % (' ' * self.width()))
   141         sys.stdout.write('\r%s\r' % (' ' * self.width()))
   142 
   142 
       
   143     def complete(self):
       
   144         if self.ui.configbool('progress', 'clear-complete', default=True):
       
   145             self.clear()
       
   146         else:
       
   147             sys.stdout.write('\n')
       
   148         sys.stdout.flush()
       
   149 
   143     def width(self):
   150     def width(self):
   144         tw = util.termwidth()
   151         tw = util.termwidth()
   145         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
   152         return min(int(self.ui.config('progress', 'width', default=tw)), tw)
   146 
   153 
   147     def progress(self, orig, topic, pos, item='', unit='', total=None):
   154     def progress(self, orig, topic, pos, item='', unit='', total=None):
   148         now = time.time()
   155         if pos is None:
   149         if pos is None and self.topics[-1] == topic and self.printed:
   156             if self.topics and self.topics[-1] == topic and self.printed:
   150             if self.ui.configbool('progress', 'clear-complete', default=True):
   157                 self.complete()
   151                 self.clear()
       
   152             else:
       
   153                 sys.stdout.write('\n')
       
   154             sys.stdout.flush()
       
   155             self.resetstate()
   158             self.resetstate()
   156         elif topic not in self.topics:
   159         else:
   157             self.topics.append(topic)
   160             if topic not in self.topics:
   158 
   161                 self.topics.append(topic)
   159         if now - self.lastprint > 0.1 and topic == self.topics[-1]:
   162             now = time.time()
   160             self.lastprint = now
   163             if now - self.lastprint > 0.1 and topic == self.topics[-1]:
   161             self.show(topic, pos, item, unit, total)
   164                 self.lastprint = now
       
   165                 self.show(topic, pos, item, unit, total)
   162         return orig(topic, pos, item=item, unit=unit, total=total)
   166         return orig(topic, pos, item=item, unit=unit, total=total)
   163 
   167 
   164     def write(self, orig, *args):
   168     def write(self, orig, *args):
   165         if self.printed:
   169         if self.printed:
   166             self.clear()
   170             self.clear()