hgext/progress.py
changeset 14838 5d261fd00446
parent 14837 ec4ba216ddef
child 15662 06671371e634
equal deleted inserted replaced
14837:ec4ba216ddef 14838:5d261fd00446
    25 
    25 
    26 The following settings are available::
    26 The following settings are available::
    27 
    27 
    28   [progress]
    28   [progress]
    29   delay = 3 # number of seconds (float) before showing the progress bar
    29   delay = 3 # number of seconds (float) before showing the progress bar
       
    30   changedelay = 1 # changedelay: minimum delay before showing a new topic.
       
    31                   # If set to less than 3 * refresh, that value will
       
    32                   # be used instead.
    30   refresh = 0.1 # time in seconds between refreshes of the progress bar
    33   refresh = 0.1 # time in seconds between refreshes of the progress bar
    31   format = topic bar number estimate # format of the progress bar
    34   format = topic bar number estimate # format of the progress bar
    32   width = <none> # if set, the maximum width of the progress information
    35   width = <none> # if set, the maximum width of the progress information
    33                  # (that is, min(width, term width) will be used)
    36                  # (that is, min(width, term width) will be used)
    34   clear-complete = True # clear the progress bar after it's done
    37   clear-complete = True # clear the progress bar after it's done
   103         self.starttimes = {}
   106         self.starttimes = {}
   104         self.startvals = {}
   107         self.startvals = {}
   105         self.printed = False
   108         self.printed = False
   106         self.lastprint = time.time() + float(self.ui.config(
   109         self.lastprint = time.time() + float(self.ui.config(
   107             'progress', 'delay', default=3))
   110             'progress', 'delay', default=3))
       
   111         self.lasttopic = None
   108         self.indetcount = 0
   112         self.indetcount = 0
   109         self.refresh = float(self.ui.config(
   113         self.refresh = float(self.ui.config(
   110             'progress', 'refresh', default=0.1))
   114             'progress', 'refresh', default=0.1))
       
   115         self.changedelay = max(3 * self.refresh,
       
   116                                float(self.ui.config(
       
   117                                    'progress', 'changedelay', default=1)))
   111         self.order = self.ui.configlist(
   118         self.order = self.ui.configlist(
   112             'progress', 'format',
   119             'progress', 'format',
   113             default=['topic', 'bar', 'number', 'estimate'])
   120             default=['topic', 'bar', 'number', 'estimate'])
   114 
   121 
   115     def show(self, now, topic, pos, item, unit, total):
   122     def show(self, now, topic, pos, item, unit, total):
   182             prog = ''.join(('[', bar , ']'))
   189             prog = ''.join(('[', bar , ']'))
   183             out = spacejoin(head, prog, tail)
   190             out = spacejoin(head, prog, tail)
   184         else:
   191         else:
   185             out = spacejoin(head, tail)
   192             out = spacejoin(head, tail)
   186         sys.stderr.write('\r' + out[:termwidth])
   193         sys.stderr.write('\r' + out[:termwidth])
       
   194         self.lasttopic = topic
   187         sys.stderr.flush()
   195         sys.stderr.flush()
   188 
   196 
   189     def clear(self):
   197     def clear(self):
   190         if not shouldprint(self.ui):
   198         if not shouldprint(self.ui):
   191             return
   199             return
   246                 self.starttimes[topic] = now
   254                 self.starttimes[topic] = now
   247                 self.startvals[topic] = pos
   255                 self.startvals[topic] = pos
   248                 self.topics.append(topic)
   256                 self.topics.append(topic)
   249             self.topicstates[topic] = pos, item, unit, total
   257             self.topicstates[topic] = pos, item, unit, total
   250             if now - self.lastprint >= self.refresh and self.topics:
   258             if now - self.lastprint >= self.refresh and self.topics:
   251                 self.lastprint = now
   259                 if (self.lasttopic is None # first time we printed
   252                 self.show(now, topic, *self.topicstates[topic])
   260                     # not a topic change
       
   261                     or topic == self.lasttopic
       
   262                     # it's been long enough we should print anyway
       
   263                     or now - self.lastprint >= self.changedelay):
       
   264                     self.lastprint = now
       
   265                     self.show(now, topic, *self.topicstates[topic])
   253 
   266 
   254 _singleton = None
   267 _singleton = None
   255 
   268 
   256 def uisetup(ui):
   269 def uisetup(ui):
   257     global _singleton
   270     global _singleton