Show More
@@ -22,6 +22,12 b' To set the pager that should be used, se' | |||
|
22 | 22 | If no pager is set, the pager extensions uses the environment variable |
|
23 | 23 | $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used. |
|
24 | 24 | |
|
25 | By default, the pager is only executed if a command has output. To | |
|
26 | force the pager to run even if a command prints nothing, set:: | |
|
27 | ||
|
28 | [pager] | |
|
29 | force = True | |
|
30 | ||
|
25 | 31 | If you notice "BROKEN PIPE" error messages, you can disable them by |
|
26 | 32 | setting:: |
|
27 | 33 | |
@@ -57,7 +63,7 b' import sys, os, signal, shlex, errno' | |||
|
57 | 63 | from mercurial import commands, dispatch, util, extensions |
|
58 | 64 | from mercurial.i18n import _ |
|
59 | 65 | |
|
60 | def _runpager(p): | |
|
66 | def _runpager(p, sigpipe=False): | |
|
61 | 67 | if not hasattr(os, 'fork'): |
|
62 | 68 | sys.stderr = sys.stdout = util.popen(p, 'wb') |
|
63 | 69 | return |
@@ -68,6 +74,8 b' def _runpager(p):' | |||
|
68 | 74 | os.dup2(fdout, sys.stdout.fileno()) |
|
69 | 75 | os.dup2(fdout, sys.stderr.fileno()) |
|
70 | 76 | os.close(fdout) |
|
77 | if sigpipe: | |
|
78 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) | |
|
71 | 79 | return |
|
72 | 80 | os.dup2(fdin, sys.stdin.fileno()) |
|
73 | 81 | os.close(fdin) |
@@ -86,6 +94,23 b' def uisetup(ui):' | |||
|
86 | 94 | if ui.plain(): |
|
87 | 95 | return |
|
88 | 96 | |
|
97 | class pagerui(ui.__class__): | |
|
98 | _pager = None | |
|
99 | _pagerstarted = False | |
|
100 | ||
|
101 | def write(self, *args, **opts): | |
|
102 | if self._pager and not self._pagerstarted: | |
|
103 | self._pagerstarted = True | |
|
104 | self._pager() | |
|
105 | return super(pagerui, self).write(*args, **opts) | |
|
106 | ||
|
107 | def write_err(self, *args, **opts): | |
|
108 | if self._pager and not self._pagerstarted: | |
|
109 | self._pagerstarted = True | |
|
110 | self._pager() | |
|
111 | return super(pagerui, self).write(*args, **opts) | |
|
112 | ui.__class__ = pagerui | |
|
113 | ||
|
89 | 114 | def pagecmd(orig, ui, options, cmd, cmdfunc): |
|
90 | 115 | p = ui.config("pager", "pager", os.environ.get("PAGER")) |
|
91 | 116 | if p and sys.stdout.isatty() and '--debugger' not in sys.argv: |
@@ -97,9 +122,11 b' def uisetup(ui):' | |||
|
97 | 122 | (cmd not in ui.configlist('pager', 'ignore') and not attend))): |
|
98 | 123 | ui.setconfig('ui', 'formatted', ui.formatted()) |
|
99 | 124 | ui.setconfig('ui', 'interactive', False) |
|
100 | _runpager(p) | |
|
101 |
if ui.configbool('pager', ' |
|
|
102 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) | |
|
125 | sigpipe = ui.configbool('pager', 'quiet') | |
|
126 | if ui.configbool('pager', 'force'): | |
|
127 | _runpager(p, sigpipe) | |
|
128 | else: | |
|
129 | ui._pager = lambda: _runpager(p, sigpipe) | |
|
103 | 130 | return orig(ui, options, cmd, cmdfunc) |
|
104 | 131 | |
|
105 | 132 | extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |
General Comments 0
You need to be logged in to leave comments.
Login now