hgext/progress.py
changeset 25499 0fa964d6fd48
parent 25498 7a5335ed7e1a
child 25520 c8fada8d9db9
equal deleted inserted replaced
25498:7a5335ed7e1a 25499:0fa964d6fd48
    33 the item, but this can be changed by adding either ``-<num>`` which
    33 the item, but this can be changed by adding either ``-<num>`` which
    34 would take the last num characters, or ``+<num>`` for the first num
    34 would take the last num characters, or ``+<num>`` for the first num
    35 characters.
    35 characters.
    36 """
    36 """
    37 
    37 
    38 from mercurial import progress
       
    39 from mercurial import ui as uimod
       
    40 
       
    41 def uisetup(ui):
    38 def uisetup(ui):
    42     class progressui(ui.__class__):
    39     if ui.config('progress', 'disable', None) is None:
    43         _progbar = None
    40         ui.setconfig('progress', 'disable', 'False', 'hgext-progress')
    44 
       
    45         def _quiet(self):
       
    46             return self.debugflag or self.quiet
       
    47 
       
    48         def progress(self, *args, **opts):
       
    49             if not self._quiet():
       
    50                 self._progbar.progress(*args, **opts)
       
    51             return super(progressui, self).progress(*args, **opts)
       
    52 
       
    53         def write(self, *args, **opts):
       
    54             if not self._quiet() and self._progbar.printed:
       
    55                 self._progbar.clear()
       
    56             return super(progressui, self).write(*args, **opts)
       
    57 
       
    58         def write_err(self, *args, **opts):
       
    59             if not self._quiet() and self._progbar.printed:
       
    60                 self._progbar.clear()
       
    61             return super(progressui, self).write_err(*args, **opts)
       
    62 
       
    63     # Apps that derive a class from ui.ui() can use
       
    64     # setconfig('progress', 'disable', 'True') to disable this extension
       
    65     if ui.configbool('progress', 'disable'):
       
    66         return
       
    67     if progress.shouldprint(ui) and not ui.debugflag and not ui.quiet:
       
    68         dval = object()
       
    69         if getattr(ui, '_progbar', dval) is dval:
       
    70             ui.__class__ = progressui
       
    71             # we instantiate one globally-shared progress bar to avoid
       
    72             # competing progress bars when multiple UI objects get created
       
    73             if not progressui._progbar:
       
    74                 progressui._progbar = uimod.getprogbar(ui)
       
    75 
    41 
    76 def reposetup(ui, repo):
    42 def reposetup(ui, repo):
    77     uisetup(repo.ui)
    43     uisetup(repo.ui)