##// END OF EJS Templates
pager: test the 'enable' config option...
Pierre-Yves David -
r32099:149440d7 stable
parent child Browse files
Show More
@@ -1,302 +1,326
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 > color = no
14 14 > [pager]
15 15 > pager = python $TESTTMP/fakepager.py
16 16 > EOF
17 17
18 18 $ hg init repo
19 19 $ cd repo
20 20 $ echo a >> a
21 21 $ hg add a
22 22 $ hg ci -m 'add a'
23 23 $ for x in `python $TESTDIR/seq.py 1 10`; do
24 24 > echo a $x >> a
25 25 > hg ci -m "modify a $x"
26 26 > done
27 27
28 28 By default diff and log are paged, but id is not:
29 29
30 30 $ hg diff -c 2 --pager=yes
31 31 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
32 32 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
33 33 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
34 34 paged! '@@ -1,2 +1,3 @@\n'
35 35 paged! ' a\n'
36 36 paged! ' a 1\n'
37 37 paged! '+a 2\n'
38 38
39 39 $ hg log --limit 2
40 40 paged! 'changeset: 10:46106edeeb38\n'
41 41 paged! 'tag: tip\n'
42 42 paged! 'user: test\n'
43 43 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
44 44 paged! 'summary: modify a 10\n'
45 45 paged! '\n'
46 46 paged! 'changeset: 9:6dd8ea7dd621\n'
47 47 paged! 'user: test\n'
48 48 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
49 49 paged! 'summary: modify a 9\n'
50 50 paged! '\n'
51 51
52 52 $ hg id
53 53 46106edeeb38 tip
54 54
55 We can control the pager from the config
56
57 $ hg log --limit 1 --config 'pager.enable=False'
58 changeset: 10:46106edeeb38
59 tag: tip
60 user: test
61 date: Thu Jan 01 00:00:00 1970 +0000
62 summary: modify a 10
63
64 $ hg log --limit 1 --config 'pager.enable=0'
65 changeset: 10:46106edeeb38
66 tag: tip
67 user: test
68 date: Thu Jan 01 00:00:00 1970 +0000
69 summary: modify a 10
70
71 $ hg log --limit 1 --config 'pager.enable=1'
72 paged! 'changeset: 10:46106edeeb38\n'
73 paged! 'tag: tip\n'
74 paged! 'user: test\n'
75 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
76 paged! 'summary: modify a 10\n'
77 paged! '\n'
78
55 79 We can enable the pager on id:
56 80
57 81 BROKEN: should be paged
58 82 $ hg --config pager.attend-id=yes id
59 83 46106edeeb38 tip
60 84
61 85 Setting attend-$COMMAND to a false value works, even with pager in
62 86 core:
63 87 $ hg --config pager.attend-diff=no diff -c 2
64 88 diff -r f4be7687d414 -r bce265549556 a
65 89 --- a/a Thu Jan 01 00:00:00 1970 +0000
66 90 +++ b/a Thu Jan 01 00:00:00 1970 +0000
67 91 @@ -1,2 +1,3 @@
68 92 a
69 93 a 1
70 94 +a 2
71 95
72 96 Command aliases should have same behavior as main command
73 97
74 98 $ hg history --limit 2
75 99 paged! 'changeset: 10:46106edeeb38\n'
76 100 paged! 'tag: tip\n'
77 101 paged! 'user: test\n'
78 102 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
79 103 paged! 'summary: modify a 10\n'
80 104 paged! '\n'
81 105 paged! 'changeset: 9:6dd8ea7dd621\n'
82 106 paged! 'user: test\n'
83 107 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
84 108 paged! 'summary: modify a 9\n'
85 109 paged! '\n'
86 110
87 111 Abbreviated command alias should also be paged
88 112
89 113 $ hg hist -l 1
90 114 paged! 'changeset: 10:46106edeeb38\n'
91 115 paged! 'tag: tip\n'
92 116 paged! 'user: test\n'
93 117 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
94 118 paged! 'summary: modify a 10\n'
95 119 paged! '\n'
96 120
97 121 Attend for an abbreviated command does not work
98 122
99 123 $ hg --config pager.attend-ident=true ident
100 124 46106edeeb38 tip
101 125
102 126 $ hg --config extensions.pager= --config pager.attend-ident=true ident
103 127 46106edeeb38 tip
104 128
105 129 Pager should not start if stdout is not a tty.
106 130
107 131 $ hg log -l1 -q --config ui.formatted=False
108 132 10:46106edeeb38
109 133
110 134 Pager should be disabled if pager.pager is empty (otherwise the output would
111 135 be silently lost.)
112 136
113 137 $ hg log -l1 -q --config pager.pager=
114 138 10:46106edeeb38
115 139
116 140 Pager with color enabled allows colors to come through by default,
117 141 even though stdout is no longer a tty.
118 142 $ cat >> $HGRCPATH <<EOF
119 143 > [ui]
120 144 > color = yes
121 145 > [color]
122 146 > mode = ansi
123 147 > EOF
124 148 $ hg log --limit 3
125 149 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
126 150 paged! 'tag: tip\n'
127 151 paged! 'user: test\n'
128 152 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
129 153 paged! 'summary: modify a 10\n'
130 154 paged! '\n'
131 155 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
132 156 paged! 'user: test\n'
133 157 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
134 158 paged! 'summary: modify a 9\n'
135 159 paged! '\n'
136 160 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
137 161 paged! 'user: test\n'
138 162 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
139 163 paged! 'summary: modify a 8\n'
140 164 paged! '\n'
141 165
142 166 An invalid pager command name is reported sensibly if we don't have to
143 167 use shell=True in the subprocess call:
144 168 $ hg log --limit 3 --config pager.pager=this-command-better-never-exist
145 169 missing pager command 'this-command-better-never-exist', skipping pager
146 170 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc)
147 171 tag: tip
148 172 user: test
149 173 date: Thu Jan 01 00:00:00 1970 +0000
150 174 summary: modify a 10
151 175
152 176 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc)
153 177 user: test
154 178 date: Thu Jan 01 00:00:00 1970 +0000
155 179 summary: modify a 9
156 180
157 181 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc)
158 182 user: test
159 183 date: Thu Jan 01 00:00:00 1970 +0000
160 184 summary: modify a 8
161 185
162 186
163 187 A complicated pager command gets worse behavior. Bonus points if you can
164 188 improve this.
165 189 $ hg log --limit 3 \
166 190 > --config pager.pager='this-command-better-never-exist --seriously' \
167 191 > 2>/dev/null || true
168 192
169 193 Pager works with shell aliases.
170 194
171 195 $ cat >> $HGRCPATH <<EOF
172 196 > [alias]
173 197 > echoa = !echo a
174 198 > EOF
175 199
176 200 $ hg echoa
177 201 a
178 202 BROKEN: should be paged
179 203 $ hg --config pager.attend-echoa=yes echoa
180 204 a
181 205
182 206 Pager works with hg aliases including environment variables.
183 207
184 208 $ cat >> $HGRCPATH <<'EOF'
185 209 > [alias]
186 210 > printa = log -T "$A\n" -r 0
187 211 > EOF
188 212
189 213 $ A=1 hg --config pager.attend-printa=yes printa
190 214 paged! '1\n'
191 215 $ A=2 hg --config pager.attend-printa=yes printa
192 216 paged! '2\n'
193 217
194 218 Something that's explicitly attended is still not paginated if the
195 219 pager is globally set to off using a flag:
196 220 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
197 221 2
198 222
199 223 Pager should not override the exit code of other commands
200 224
201 225 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
202 226 > from mercurial import cmdutil, commands
203 227 > cmdtable = {}
204 228 > command = cmdutil.command(cmdtable)
205 229 > @command('fortytwo', [], 'fortytwo', norepo=True)
206 230 > def fortytwo(ui, *opts):
207 231 > ui.write('42\n')
208 232 > return 42
209 233 > EOF
210 234
211 235 $ cat >> $HGRCPATH <<'EOF'
212 236 > [extensions]
213 237 > fortytwo = $TESTTMP/fortytwo.py
214 238 > EOF
215 239
216 240 $ hg fortytwo --pager=on
217 241 paged! '42\n'
218 242 [42]
219 243
220 244 A command that asks for paging using ui.pager() directly works:
221 245 $ hg blame a
222 246 paged! ' 0: a\n'
223 247 paged! ' 1: a 1\n'
224 248 paged! ' 2: a 2\n'
225 249 paged! ' 3: a 3\n'
226 250 paged! ' 4: a 4\n'
227 251 paged! ' 5: a 5\n'
228 252 paged! ' 6: a 6\n'
229 253 paged! ' 7: a 7\n'
230 254 paged! ' 8: a 8\n'
231 255 paged! ' 9: a 9\n'
232 256 paged! '10: a 10\n'
233 257 but not with HGPLAIN
234 258 $ HGPLAIN=1 hg blame a
235 259 0: a
236 260 1: a 1
237 261 2: a 2
238 262 3: a 3
239 263 4: a 4
240 264 5: a 5
241 265 6: a 6
242 266 7: a 7
243 267 8: a 8
244 268 9: a 9
245 269 10: a 10
246 270 explicit flags work too:
247 271 $ hg blame --pager=no a
248 272 0: a
249 273 1: a 1
250 274 2: a 2
251 275 3: a 3
252 276 4: a 4
253 277 5: a 5
254 278 6: a 6
255 279 7: a 7
256 280 8: a 8
257 281 9: a 9
258 282 10: a 10
259 283
260 284 Put annotate in the ignore list for pager:
261 285 $ cat >> $HGRCPATH <<EOF
262 286 > [pager]
263 287 > ignore = annotate
264 288 > EOF
265 289 $ hg blame a
266 290 0: a
267 291 1: a 1
268 292 2: a 2
269 293 3: a 3
270 294 4: a 4
271 295 5: a 5
272 296 6: a 6
273 297 7: a 7
274 298 8: a 8
275 299 9: a 9
276 300 10: a 10
277 301
278 302 Environment variables like LESS and LV are set automatically:
279 303 $ cat > $TESTTMP/printlesslv.py <<EOF
280 304 > import os, sys
281 305 > sys.stdin.read()
282 306 > for name in ['LESS', 'LV']:
283 307 > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-')))
284 308 > sys.stdout.flush()
285 309 > EOF
286 310
287 311 $ cat >> $HGRCPATH <<EOF
288 312 > [alias]
289 313 > noop = log -r 0 -T ''
290 314 > [ui]
291 315 > formatted=1
292 316 > [pager]
293 317 > pager = $PYTHON $TESTTMP/printlesslv.py
294 318 > EOF
295 319 $ unset LESS
296 320 $ unset LV
297 321 $ hg noop --pager=on
298 322 LESS=FRX
299 323 LV=-c
300 324 $ LESS=EFGH hg noop --pager=on
301 325 LESS=EFGH
302 326 LV=-c
General Comments 0
You need to be logged in to leave comments. Login now