Show More
@@ -22,6 +22,12 b' To set the pager that should be used, se' | |||||
22 | If no pager is set, the pager extensions uses the environment variable |
|
22 | If no pager is set, the pager extensions uses the environment variable | |
23 | $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used. |
|
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 | If you notice "BROKEN PIPE" error messages, you can disable them by |
|
31 | If you notice "BROKEN PIPE" error messages, you can disable them by | |
26 | setting:: |
|
32 | setting:: | |
27 |
|
33 | |||
@@ -57,7 +63,7 b' import sys, os, signal, shlex, errno' | |||||
57 | from mercurial import commands, dispatch, util, extensions |
|
63 | from mercurial import commands, dispatch, util, extensions | |
58 | from mercurial.i18n import _ |
|
64 | from mercurial.i18n import _ | |
59 |
|
65 | |||
60 | def _runpager(p): |
|
66 | def _runpager(p, sigpipe=False): | |
61 | if not hasattr(os, 'fork'): |
|
67 | if not hasattr(os, 'fork'): | |
62 | sys.stderr = sys.stdout = util.popen(p, 'wb') |
|
68 | sys.stderr = sys.stdout = util.popen(p, 'wb') | |
63 | return |
|
69 | return | |
@@ -68,6 +74,8 b' def _runpager(p):' | |||||
68 | os.dup2(fdout, sys.stdout.fileno()) |
|
74 | os.dup2(fdout, sys.stdout.fileno()) | |
69 | os.dup2(fdout, sys.stderr.fileno()) |
|
75 | os.dup2(fdout, sys.stderr.fileno()) | |
70 | os.close(fdout) |
|
76 | os.close(fdout) | |
|
77 | if sigpipe: | |||
|
78 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) | |||
71 | return |
|
79 | return | |
72 | os.dup2(fdin, sys.stdin.fileno()) |
|
80 | os.dup2(fdin, sys.stdin.fileno()) | |
73 | os.close(fdin) |
|
81 | os.close(fdin) | |
@@ -86,6 +94,23 b' def uisetup(ui):' | |||||
86 | if ui.plain(): |
|
94 | if ui.plain(): | |
87 | return |
|
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 | def pagecmd(orig, ui, options, cmd, cmdfunc): |
|
114 | def pagecmd(orig, ui, options, cmd, cmdfunc): | |
90 | p = ui.config("pager", "pager", os.environ.get("PAGER")) |
|
115 | p = ui.config("pager", "pager", os.environ.get("PAGER")) | |
91 | if p and sys.stdout.isatty() and '--debugger' not in sys.argv: |
|
116 | if p and sys.stdout.isatty() and '--debugger' not in sys.argv: | |
@@ -97,9 +122,11 b' def uisetup(ui):' | |||||
97 | (cmd not in ui.configlist('pager', 'ignore') and not attend))): |
|
122 | (cmd not in ui.configlist('pager', 'ignore') and not attend))): | |
98 | ui.setconfig('ui', 'formatted', ui.formatted()) |
|
123 | ui.setconfig('ui', 'formatted', ui.formatted()) | |
99 | ui.setconfig('ui', 'interactive', False) |
|
124 | ui.setconfig('ui', 'interactive', False) | |
100 | _runpager(p) |
|
125 | sigpipe = ui.configbool('pager', 'quiet') | |
101 |
if ui.configbool('pager', ' |
|
126 | if ui.configbool('pager', 'force'): | |
102 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
|
127 | _runpager(p, sigpipe) | |
|
128 | else: | |||
|
129 | ui._pager = lambda: _runpager(p, sigpipe) | |||
103 | return orig(ui, options, cmd, cmdfunc) |
|
130 | return orig(ui, options, cmd, cmdfunc) | |
104 |
|
131 | |||
105 | extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |
|
132 | extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |
General Comments 0
You need to be logged in to leave comments.
Login now