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