##// END OF EJS Templates
pager: if old pager extensions is enabled, respect pager.attend...
Martin von Zweigbergk -
r31406:e83302d4 default
parent child Browse files
Show More
@@ -1,73 +1,73 b''
1 # pager.py - display output using a pager
1 # pager.py - display output using a pager
2 #
2 #
3 # Copyright 2008 David Soria Parra <dsp@php.net>
3 # Copyright 2008 David Soria Parra <dsp@php.net>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 #
7 #
8 # To load the extension, add it to your configuration file:
8 # To load the extension, add it to your configuration file:
9 #
9 #
10 # [extension]
10 # [extension]
11 # pager =
11 # pager =
12 #
12 #
13 # Run 'hg help pager' to get info on configuration.
13 # Run 'hg help pager' to get info on configuration.
14
14
15 '''browse command output with an external pager (DEPRECATED)
15 '''browse command output with an external pager (DEPRECATED)
16
16
17 Forcibly enable paging for individual commands that don't typically
17 Forcibly enable paging for individual commands that don't typically
18 request pagination with the attend-<command> option. This setting
18 request pagination with the attend-<command> option. This setting
19 takes precedence over ignore options and defaults::
19 takes precedence over ignore options and defaults::
20
20
21 [pager]
21 [pager]
22 attend-cat = false
22 attend-cat = false
23 '''
23 '''
24 from __future__ import absolute_import
24 from __future__ import absolute_import
25
25
26 from mercurial import (
26 from mercurial import (
27 cmdutil,
27 cmdutil,
28 commands,
28 commands,
29 dispatch,
29 dispatch,
30 extensions,
30 extensions,
31 )
31 )
32
32
33 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
33 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
34 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
34 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
35 # be specifying the version(s) of Mercurial they are tested with, or
35 # be specifying the version(s) of Mercurial they are tested with, or
36 # leave the attribute unspecified.
36 # leave the attribute unspecified.
37 testedwith = 'ships-with-hg-core'
37 testedwith = 'ships-with-hg-core'
38
38
39 def uisetup(ui):
39 def uisetup(ui):
40
40
41 def pagecmd(orig, ui, options, cmd, cmdfunc):
41 def pagecmd(orig, ui, options, cmd, cmdfunc):
42 auto = options['pager'] == 'auto'
42 auto = options['pager'] == 'auto'
43 if auto and not ui.pageractive:
43 if auto and not ui.pageractive:
44 usepager = False
44 usepager = False
45 attend = ui.configlist('pager', 'attend', attended)
45 attend = ui.configlist('pager', 'attend', attended)
46 ignore = ui.configlist('pager', 'ignore')
46 ignore = ui.configlist('pager', 'ignore')
47 cmds, _ = cmdutil.findcmd(cmd, commands.table)
47 cmds, _ = cmdutil.findcmd(cmd, commands.table)
48
48
49 for cmd in cmds:
49 for cmd in cmds:
50 var = 'attend-%s' % cmd
50 var = 'attend-%s' % cmd
51 if ui.config('pager', var):
51 if ui.config('pager', var):
52 usepager = ui.configbool('pager', var)
52 usepager = ui.configbool('pager', var)
53 break
53 break
54 if (cmd in attend or
54 if (cmd in attend or
55 (cmd not in ignore and not attend)):
55 (cmd not in ignore and not attend)):
56 usepager = True
56 usepager = True
57 break
57 break
58
58
59 if usepager:
59 if usepager:
60 # Slight hack: the attend list is supposed to override
60 # Slight hack: the attend list is supposed to override
61 # the ignore list for the pager extension, but the
61 # the ignore list for the pager extension, but the
62 # core code doesn't know about attend, so we have to
62 # core code doesn't know about attend, so we have to
63 # lobotomize the ignore list so that the extension's
63 # lobotomize the ignore list so that the extension's
64 # behavior is preserved.
64 # behavior is preserved.
65 ui.setconfig('pager', 'ignore', '', 'pager')
65 ui.setconfig('pager', 'ignore', '', 'pager')
66 ui.pager('extension-via-attend-' + cmd)
66 ui.pager('extension-via-attend-' + cmd)
67 else:
68 ui.disablepager()
67 return orig(ui, options, cmd, cmdfunc)
69 return orig(ui, options, cmd, cmdfunc)
68
70
69 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
71 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
70
72
71 attended = [
73 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
72 'the-default-attend-list-is-now-empty-but-that-breaks-the-extension',
73 ]
@@ -1,234 +1,232 b''
1 $ cat >> fakepager.py <<EOF
1 $ cat >> fakepager.py <<EOF
2 > import sys
2 > import sys
3 > for line in sys.stdin:
3 > for line in sys.stdin:
4 > sys.stdout.write('paged! %r\n' % line)
4 > sys.stdout.write('paged! %r\n' % line)
5 > EOF
5 > EOF
6
6
7 Enable ui.formatted because pager won't fire without it, and set up
7 Enable ui.formatted because pager won't fire without it, and set up
8 pager and tell it to use our fake pager that lets us see when the
8 pager and tell it to use our fake pager that lets us see when the
9 pager was running.
9 pager was running.
10 $ cat >> $HGRCPATH <<EOF
10 $ cat >> $HGRCPATH <<EOF
11 > [ui]
11 > [ui]
12 > formatted = yes
12 > formatted = yes
13 > [extensions]
13 > [extensions]
14 > pager=
14 > pager=
15 > [pager]
15 > [pager]
16 > pager = python $TESTTMP/fakepager.py
16 > pager = python $TESTTMP/fakepager.py
17 > EOF
17 > EOF
18
18
19 $ hg init repo
19 $ hg init repo
20 $ cd repo
20 $ cd repo
21 $ echo a >> a
21 $ echo a >> a
22 $ hg add a
22 $ hg add a
23 $ hg ci -m 'add a'
23 $ hg ci -m 'add a'
24 $ for x in `python $TESTDIR/seq.py 1 10`; do
24 $ for x in `python $TESTDIR/seq.py 1 10`; do
25 > echo a $x >> a
25 > echo a $x >> a
26 > hg ci -m "modify a $x"
26 > hg ci -m "modify a $x"
27 > done
27 > done
28
28
29 By default diff and log are paged, but summary is not:
29 By default diff and log are paged, but summary is not:
30
30
31 $ hg diff -c 2 --pager=yes
31 $ hg diff -c 2 --pager=yes
32 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
32 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
33 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
33 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
34 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
34 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
35 paged! '@@ -1,2 +1,3 @@\n'
35 paged! '@@ -1,2 +1,3 @@\n'
36 paged! ' a\n'
36 paged! ' a\n'
37 paged! ' a 1\n'
37 paged! ' a 1\n'
38 paged! '+a 2\n'
38 paged! '+a 2\n'
39
39
40 $ hg log --limit 2
40 $ hg log --limit 2
41 paged! 'changeset: 10:46106edeeb38\n'
41 paged! 'changeset: 10:46106edeeb38\n'
42 paged! 'tag: tip\n'
42 paged! 'tag: tip\n'
43 paged! 'user: test\n'
43 paged! 'user: test\n'
44 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
44 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
45 paged! 'summary: modify a 10\n'
45 paged! 'summary: modify a 10\n'
46 paged! '\n'
46 paged! '\n'
47 paged! 'changeset: 9:6dd8ea7dd621\n'
47 paged! 'changeset: 9:6dd8ea7dd621\n'
48 paged! 'user: test\n'
48 paged! 'user: test\n'
49 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
49 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
50 paged! 'summary: modify a 9\n'
50 paged! 'summary: modify a 9\n'
51 paged! '\n'
51 paged! '\n'
52
52
53 BROKEN: should not be paged by default
54 $ hg summary
53 $ hg summary
55 paged! 'parent: 10:46106edeeb38 tip\n'
54 parent: 10:46106edeeb38 tip
56 paged! ' modify a 10\n'
55 modify a 10
57 paged! 'branch: default\n'
56 branch: default
58 paged! 'commit: (clean)\n'
57 commit: (clean)
59 paged! 'update: (current)\n'
58 update: (current)
60 paged! 'phases: 11 draft\n'
59 phases: 11 draft
61
60
62 We can enable the pager on summary:
61 We can enable the pager on summary:
63
62
64 $ hg --config pager.attend-summary=yes summary
63 $ hg --config pager.attend-summary=yes summary
65 paged! 'parent: 10:46106edeeb38 tip\n'
64 paged! 'parent: 10:46106edeeb38 tip\n'
66 paged! ' modify a 10\n'
65 paged! ' modify a 10\n'
67 paged! 'branch: default\n'
66 paged! 'branch: default\n'
68 paged! 'commit: (clean)\n'
67 paged! 'commit: (clean)\n'
69 paged! 'update: (current)\n'
68 paged! 'update: (current)\n'
70 paged! 'phases: 11 draft\n'
69 paged! 'phases: 11 draft\n'
71
70
72 $ hg --config pager.attend-diff=no diff -c 2
71 $ hg --config pager.attend-diff=no diff -c 2
73 diff -r f4be7687d414 -r bce265549556 a
72 diff -r f4be7687d414 -r bce265549556 a
74 --- a/a Thu Jan 01 00:00:00 1970 +0000
73 --- a/a Thu Jan 01 00:00:00 1970 +0000
75 +++ b/a Thu Jan 01 00:00:00 1970 +0000
74 +++ b/a Thu Jan 01 00:00:00 1970 +0000
76 @@ -1,2 +1,3 @@
75 @@ -1,2 +1,3 @@
77 a
76 a
78 a 1
77 a 1
79 +a 2
78 +a 2
80
79
81 If we completely change the attend list that's respected:
80 If we completely change the attend list that's respected:
82 BROKEN: diff should not be paged
83 $ hg --config pager.attend=summary diff -c 2
81 $ hg --config pager.attend=summary diff -c 2
84 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
82 diff -r f4be7687d414 -r bce265549556 a
85 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
83 --- a/a Thu Jan 01 00:00:00 1970 +0000
86 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
84 +++ b/a Thu Jan 01 00:00:00 1970 +0000
87 paged! '@@ -1,2 +1,3 @@\n'
85 @@ -1,2 +1,3 @@
88 paged! ' a\n'
86 a
89 paged! ' a 1\n'
87 a 1
90 paged! '+a 2\n'
88 +a 2
91
89
92 If 'log' is in attend, then 'history' should also be paged:
90 If 'log' is in attend, then 'history' should also be paged:
93 $ hg history --limit 2 --config pager.attend=log
91 $ hg history --limit 2 --config pager.attend=log
94 paged! 'changeset: 10:46106edeeb38\n'
92 paged! 'changeset: 10:46106edeeb38\n'
95 paged! 'tag: tip\n'
93 paged! 'tag: tip\n'
96 paged! 'user: test\n'
94 paged! 'user: test\n'
97 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
95 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
98 paged! 'summary: modify a 10\n'
96 paged! 'summary: modify a 10\n'
99 paged! '\n'
97 paged! '\n'
100 paged! 'changeset: 9:6dd8ea7dd621\n'
98 paged! 'changeset: 9:6dd8ea7dd621\n'
101 paged! 'user: test\n'
99 paged! 'user: test\n'
102 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
100 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
103 paged! 'summary: modify a 9\n'
101 paged! 'summary: modify a 9\n'
104 paged! '\n'
102 paged! '\n'
105
103
106 Possible bug: history is explicitly ignored in pager config, but
104 Possible bug: history is explicitly ignored in pager config, but
107 because log is in the attend list it still gets pager treatment.
105 because log is in the attend list it still gets pager treatment.
108
106
109 $ hg history --limit 2 --config pager.attend=log \
107 $ hg history --limit 2 --config pager.attend=log \
110 > --config pager.ignore=history
108 > --config pager.ignore=history
111 paged! 'changeset: 10:46106edeeb38\n'
109 paged! 'changeset: 10:46106edeeb38\n'
112 paged! 'tag: tip\n'
110 paged! 'tag: tip\n'
113 paged! 'user: test\n'
111 paged! 'user: test\n'
114 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
112 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
115 paged! 'summary: modify a 10\n'
113 paged! 'summary: modify a 10\n'
116 paged! '\n'
114 paged! '\n'
117 paged! 'changeset: 9:6dd8ea7dd621\n'
115 paged! 'changeset: 9:6dd8ea7dd621\n'
118 paged! 'user: test\n'
116 paged! 'user: test\n'
119 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
117 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
120 paged! 'summary: modify a 9\n'
118 paged! 'summary: modify a 9\n'
121 paged! '\n'
119 paged! '\n'
122
120
123 Possible bug: history is explicitly marked as attend-history=no, but
121 Possible bug: history is explicitly marked as attend-history=no, but
124 it doesn't fail to get paged because log is still in the attend list.
122 it doesn't fail to get paged because log is still in the attend list.
125
123
126 $ hg history --limit 2 --config pager.attend-history=no
124 $ hg history --limit 2 --config pager.attend-history=no
127 paged! 'changeset: 10:46106edeeb38\n'
125 paged! 'changeset: 10:46106edeeb38\n'
128 paged! 'tag: tip\n'
126 paged! 'tag: tip\n'
129 paged! 'user: test\n'
127 paged! 'user: test\n'
130 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
128 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
131 paged! 'summary: modify a 10\n'
129 paged! 'summary: modify a 10\n'
132 paged! '\n'
130 paged! '\n'
133 paged! 'changeset: 9:6dd8ea7dd621\n'
131 paged! 'changeset: 9:6dd8ea7dd621\n'
134 paged! 'user: test\n'
132 paged! 'user: test\n'
135 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
133 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
136 paged! 'summary: modify a 9\n'
134 paged! 'summary: modify a 9\n'
137 paged! '\n'
135 paged! '\n'
138
136
139 Possible bug: disabling pager for log but enabling it for history
137 Possible bug: disabling pager for log but enabling it for history
140 doesn't result in history being paged.
138 doesn't result in history being paged.
141
139
142 $ hg history --limit 2 --config pager.attend-log=no \
140 $ hg history --limit 2 --config pager.attend-log=no \
143 > --config pager.attend-history=yes
141 > --config pager.attend-history=yes
144 changeset: 10:46106edeeb38
142 changeset: 10:46106edeeb38
145 tag: tip
143 tag: tip
146 user: test
144 user: test
147 date: Thu Jan 01 00:00:00 1970 +0000
145 date: Thu Jan 01 00:00:00 1970 +0000
148 summary: modify a 10
146 summary: modify a 10
149
147
150 changeset: 9:6dd8ea7dd621
148 changeset: 9:6dd8ea7dd621
151 user: test
149 user: test
152 date: Thu Jan 01 00:00:00 1970 +0000
150 date: Thu Jan 01 00:00:00 1970 +0000
153 summary: modify a 9
151 summary: modify a 9
154
152
155 Pager should not start if stdout is not a tty.
153 Pager should not start if stdout is not a tty.
156
154
157 $ hg log -l1 -q --config ui.formatted=False
155 $ hg log -l1 -q --config ui.formatted=False
158 10:46106edeeb38
156 10:46106edeeb38
159
157
160 Pager with color enabled allows colors to come through by default,
158 Pager with color enabled allows colors to come through by default,
161 even though stdout is no longer a tty.
159 even though stdout is no longer a tty.
162 $ cat >> $HGRCPATH <<EOF
160 $ cat >> $HGRCPATH <<EOF
163 > [extensions]
161 > [extensions]
164 > color=
162 > color=
165 > [color]
163 > [color]
166 > mode = ansi
164 > mode = ansi
167 > EOF
165 > EOF
168 $ hg log --limit 3
166 $ hg log --limit 3
169 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
167 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
170 paged! 'tag: tip\n'
168 paged! 'tag: tip\n'
171 paged! 'user: test\n'
169 paged! 'user: test\n'
172 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
170 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
173 paged! 'summary: modify a 10\n'
171 paged! 'summary: modify a 10\n'
174 paged! '\n'
172 paged! '\n'
175 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
173 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
176 paged! 'user: test\n'
174 paged! 'user: test\n'
177 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
175 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
178 paged! 'summary: modify a 9\n'
176 paged! 'summary: modify a 9\n'
179 paged! '\n'
177 paged! '\n'
180 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
178 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
181 paged! 'user: test\n'
179 paged! 'user: test\n'
182 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
180 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
183 paged! 'summary: modify a 8\n'
181 paged! 'summary: modify a 8\n'
184 paged! '\n'
182 paged! '\n'
185
183
186 Pager works with shell aliases.
184 Pager works with shell aliases.
187
185
188 $ cat >> $HGRCPATH <<EOF
186 $ cat >> $HGRCPATH <<EOF
189 > [alias]
187 > [alias]
190 > echoa = !echo a
188 > echoa = !echo a
191 > EOF
189 > EOF
192
190
193 $ hg echoa
191 $ hg echoa
194 a
192 a
195 $ hg --config pager.attend-echoa=yes echoa
193 $ hg --config pager.attend-echoa=yes echoa
196 paged! 'a\n'
194 paged! 'a\n'
197
195
198 Pager works with hg aliases including environment variables.
196 Pager works with hg aliases including environment variables.
199
197
200 $ cat >> $HGRCPATH <<'EOF'
198 $ cat >> $HGRCPATH <<'EOF'
201 > [alias]
199 > [alias]
202 > printa = log -T "$A\n" -r 0
200 > printa = log -T "$A\n" -r 0
203 > EOF
201 > EOF
204
202
205 $ A=1 hg --config pager.attend-printa=yes printa
203 $ A=1 hg --config pager.attend-printa=yes printa
206 paged! '1\n'
204 paged! '1\n'
207 $ A=2 hg --config pager.attend-printa=yes printa
205 $ A=2 hg --config pager.attend-printa=yes printa
208 paged! '2\n'
206 paged! '2\n'
209
207
210 Something that's explicitly attended is still not paginated if the
208 Something that's explicitly attended is still not paginated if the
211 pager is globally set to off using a flag:
209 pager is globally set to off using a flag:
212 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
210 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
213 2
211 2
214
212
215 Pager should not override the exit code of other commands
213 Pager should not override the exit code of other commands
216
214
217 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
215 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
218 > from mercurial import cmdutil, commands
216 > from mercurial import cmdutil, commands
219 > cmdtable = {}
217 > cmdtable = {}
220 > command = cmdutil.command(cmdtable)
218 > command = cmdutil.command(cmdtable)
221 > @command('fortytwo', [], 'fortytwo', norepo=True)
219 > @command('fortytwo', [], 'fortytwo', norepo=True)
222 > def fortytwo(ui, *opts):
220 > def fortytwo(ui, *opts):
223 > ui.write('42\n')
221 > ui.write('42\n')
224 > return 42
222 > return 42
225 > EOF
223 > EOF
226
224
227 $ cat >> $HGRCPATH <<'EOF'
225 $ cat >> $HGRCPATH <<'EOF'
228 > [extensions]
226 > [extensions]
229 > fortytwo = $TESTTMP/fortytwo.py
227 > fortytwo = $TESTTMP/fortytwo.py
230 > EOF
228 > EOF
231
229
232 $ hg fortytwo --pager=on
230 $ hg fortytwo --pager=on
233 paged! '42\n'
231 paged! '42\n'
234 [42]
232 [42]
General Comments 0
You need to be logged in to leave comments. Login now