hgext/pager.py
changeset 7216 292fb2ad2846
parent 6548 962eb403165b
child 7995 b8e5d9487504
equal deleted inserted replaced
7215:0ab5f21c390b 7216:292fb2ad2846
    45 To ignore global commands like "hg version" or "hg help", you have to specify
    45 To ignore global commands like "hg version" or "hg help", you have to specify
    46 them in the global .hgrc
    46 them in the global .hgrc
    47 '''
    47 '''
    48 
    48 
    49 import sys, os, signal
    49 import sys, os, signal
    50 from mercurial import dispatch, util
    50 from mercurial import dispatch, util, extensions
    51 
    51 
    52 def uisetup(ui):
    52 def uisetup(ui):
    53     def pagecmd(ui, options, cmd, cmdfunc):
    53     def pagecmd(orig, ui, options, cmd, cmdfunc):
    54         p = ui.config("pager", "pager", os.environ.get("PAGER"))
    54         p = ui.config("pager", "pager", os.environ.get("PAGER"))
    55         if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
    55         if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
    56             attend = ui.configlist('pager', 'attend')
    56             attend = ui.configlist('pager', 'attend')
    57             if (cmd in attend or
    57             if (cmd in attend or
    58                 (cmd not in ui.configlist('pager', 'ignore') and not attend)):
    58                 (cmd not in ui.configlist('pager', 'ignore') and not attend)):
    59                 sys.stderr = sys.stdout = util.popen(p, "wb")
    59                 sys.stderr = sys.stdout = util.popen(p, "wb")
    60                 if ui.configbool('pager', 'quiet'):
    60                 if ui.configbool('pager', 'quiet'):
    61                     signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    61                     signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    62         return oldrun(ui, options, cmd, cmdfunc)
    62         return orig(ui, options, cmd, cmdfunc)
    63 
    63 
    64     oldrun = dispatch._runcommand
    64     extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
    65     dispatch._runcommand = pagecmd