##// END OF EJS Templates
windows: add windows behavior on broken pager...
Raphaël Gomès -
r48414:9aad229a default
parent child Browse files
Show More
@@ -1,416 +1,438 b''
1 1 $ cat >> fakepager.py <<EOF
2 2 > import sys
3 3 > printed = False
4 4 > for line in sys.stdin:
5 5 > sys.stdout.write('paged! %r\n' % line)
6 6 > printed = True
7 7 > if not printed:
8 8 > sys.stdout.write('paged empty output!\n')
9 9 > EOF
10 10
11 11 Enable ui.formatted because pager won't fire without it, and set up
12 12 pager and tell it to use our fake pager that lets us see when the
13 13 pager was running.
14 14 $ cat >> $HGRCPATH <<EOF
15 15 > [ui]
16 16 > formatted = yes
17 17 > color = no
18 18 > [pager]
19 19 > pager = "$PYTHON" $TESTTMP/fakepager.py
20 20 > EOF
21 21
22 22 $ hg init repo
23 23 $ cd repo
24 24 $ echo a >> a
25 25 $ hg add a
26 26 $ hg ci -m 'add a'
27 27 $ for x in `"$PYTHON" $TESTDIR/seq.py 1 10`; do
28 28 > echo a $x >> a
29 29 > hg ci -m "modify a $x"
30 30 > done
31 31
32 32 By default diff and log are paged, but id is not:
33 33
34 34 $ hg diff -c 2 --pager=yes
35 35 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
36 36 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
37 37 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
38 38 paged! '@@ -1,2 +1,3 @@\n'
39 39 paged! ' a\n'
40 40 paged! ' a 1\n'
41 41 paged! '+a 2\n'
42 42
43 43 $ hg log --limit 2
44 44 paged! 'changeset: 10:46106edeeb38\n'
45 45 paged! 'tag: tip\n'
46 46 paged! 'user: test\n'
47 47 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
48 48 paged! 'summary: modify a 10\n'
49 49 paged! '\n'
50 50 paged! 'changeset: 9:6dd8ea7dd621\n'
51 51 paged! 'user: test\n'
52 52 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
53 53 paged! 'summary: modify a 9\n'
54 54 paged! '\n'
55 55
56 56 $ hg id
57 57 46106edeeb38 tip
58 58
59 59 We can control the pager from the config
60 60
61 61 $ hg log --limit 1 --config 'ui.paginate=False'
62 62 changeset: 10:46106edeeb38
63 63 tag: tip
64 64 user: test
65 65 date: Thu Jan 01 00:00:00 1970 +0000
66 66 summary: modify a 10
67 67
68 68 $ hg log --limit 1 --config 'ui.paginate=0'
69 69 changeset: 10:46106edeeb38
70 70 tag: tip
71 71 user: test
72 72 date: Thu Jan 01 00:00:00 1970 +0000
73 73 summary: modify a 10
74 74
75 75 $ hg log --limit 1 --config 'ui.paginate=1'
76 76 paged! 'changeset: 10:46106edeeb38\n'
77 77 paged! 'tag: tip\n'
78 78 paged! 'user: test\n'
79 79 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
80 80 paged! 'summary: modify a 10\n'
81 81 paged! '\n'
82 82
83 83 explicit --pager=on should take precedence over other configurations
84 84 (issue5580)
85 85
86 86 $ cat >> $HGRCPATH <<EOF
87 87 > [ui]
88 88 > paginate = false
89 89 > EOF
90 90 $ hg log --limit 1 --pager=on
91 91 paged! 'changeset: 10:46106edeeb38\n'
92 92 paged! 'tag: tip\n'
93 93 paged! 'user: test\n'
94 94 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
95 95 paged! 'summary: modify a 10\n'
96 96 paged! '\n'
97 97
98 98 $ cat >> $HGRCPATH <<EOF
99 99 > [ui]
100 100 > # true is default value of ui.paginate
101 101 > paginate = true
102 102 > EOF
103 103 $ hg log --limit 1 --pager=off
104 104 changeset: 10:46106edeeb38
105 105 tag: tip
106 106 user: test
107 107 date: Thu Jan 01 00:00:00 1970 +0000
108 108 summary: modify a 10
109 109
110 110
111 111 We can enable the pager on id:
112 112
113 113 BROKEN: should be paged
114 114 $ hg --config pager.attend-id=yes id
115 115 46106edeeb38 tip
116 116
117 117 Setting attend-$COMMAND to a false value works, even with pager in
118 118 core:
119 119 $ hg --config pager.attend-diff=no diff -c 2
120 120 diff -r f4be7687d414 -r bce265549556 a
121 121 --- a/a Thu Jan 01 00:00:00 1970 +0000
122 122 +++ b/a Thu Jan 01 00:00:00 1970 +0000
123 123 @@ -1,2 +1,3 @@
124 124 a
125 125 a 1
126 126 +a 2
127 127
128 128 Command aliases should have same behavior as main command
129 129
130 130 $ hg history --limit 2
131 131 paged! 'changeset: 10:46106edeeb38\n'
132 132 paged! 'tag: tip\n'
133 133 paged! 'user: test\n'
134 134 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
135 135 paged! 'summary: modify a 10\n'
136 136 paged! '\n'
137 137 paged! 'changeset: 9:6dd8ea7dd621\n'
138 138 paged! 'user: test\n'
139 139 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
140 140 paged! 'summary: modify a 9\n'
141 141 paged! '\n'
142 142
143 143 Abbreviated command alias should also be paged
144 144
145 145 $ hg hist -l 1
146 146 paged! 'changeset: 10:46106edeeb38\n'
147 147 paged! 'tag: tip\n'
148 148 paged! 'user: test\n'
149 149 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
150 150 paged! 'summary: modify a 10\n'
151 151 paged! '\n'
152 152
153 153 Attend for an abbreviated command does not work
154 154
155 155 $ hg --config pager.attend-ident=true ident
156 156 46106edeeb38 tip
157 157
158 158 $ hg --config extensions.pager= --config pager.attend-ident=true ident
159 159 46106edeeb38 tip
160 160
161 161 Pager should not start if stdout is not a tty.
162 162
163 163 $ hg log -l1 -q --config ui.formatted=False
164 164 10:46106edeeb38
165 165
166 166 Pager should be disabled if pager.pager is empty (otherwise the output would
167 167 be silently lost.)
168 168
169 169 $ hg log -l1 -q --config pager.pager=
170 170 10:46106edeeb38
171 171
172 172 Pager with color enabled allows colors to come through by default,
173 173 even though stdout is no longer a tty.
174 174 $ cat >> $HGRCPATH <<EOF
175 175 > [ui]
176 176 > color = always
177 177 > [color]
178 178 > mode = ansi
179 179 > EOF
180 180 $ hg log --limit 3
181 181 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
182 182 paged! 'tag: tip\n'
183 183 paged! 'user: test\n'
184 184 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
185 185 paged! 'summary: modify a 10\n'
186 186 paged! '\n'
187 187 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
188 188 paged! 'user: test\n'
189 189 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
190 190 paged! 'summary: modify a 9\n'
191 191 paged! '\n'
192 192 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
193 193 paged! 'user: test\n'
194 194 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
195 195 paged! 'summary: modify a 8\n'
196 196 paged! '\n'
197 197
198 198 #if no-chg
199 199 An invalid pager command name is reported sensibly if we don't have to
200 200 use shell=True in the subprocess call:
201 201 $ hg log --limit 3 --config pager.pager=this-command-better-never-exist
202 202 missing pager command 'this-command-better-never-exist', skipping pager
203 203 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc)
204 204 tag: tip
205 205 user: test
206 206 date: Thu Jan 01 00:00:00 1970 +0000
207 207 summary: modify a 10
208 208
209 209 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc)
210 210 user: test
211 211 date: Thu Jan 01 00:00:00 1970 +0000
212 212 summary: modify a 9
213 213
214 214 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc)
215 215 user: test
216 216 date: Thu Jan 01 00:00:00 1970 +0000
217 217 summary: modify a 8
218 218
219 219 #endif
220 220
221 221 A complicated pager command gets worse behavior. Bonus points if you can
222 improve this.
222 improve this. Windows apparently does this better?
223 #if windows
223 224 $ hg log --limit 3 \
224 225 > --config pager.pager='this-command-better-never-exist --seriously' \
225 226 > 2>/dev/null || true
227 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc)
228 tag: tip
229 user: test
230 date: Thu Jan 01 00:00:00 1970 +0000
231 summary: modify a 10
232
233 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc)
234 user: test
235 date: Thu Jan 01 00:00:00 1970 +0000
236 summary: modify a 9
237
238 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc)
239 user: test
240 date: Thu Jan 01 00:00:00 1970 +0000
241 summary: modify a 8
242
243 #else
244 $ hg log --limit 3 \
245 > --config pager.pager='this-command-better-never-exist --seriously' \
246 > 2>/dev/null || true
247 #endif
226 248
227 249 Pager works with shell aliases.
228 250
229 251 $ cat >> $HGRCPATH <<EOF
230 252 > [alias]
231 253 > echoa = !echo a
232 254 > EOF
233 255
234 256 $ hg echoa
235 257 a
236 258 BROKEN: should be paged
237 259 $ hg --config pager.attend-echoa=yes echoa
238 260 a
239 261
240 262 Pager works with hg aliases including environment variables.
241 263
242 264 $ cat >> $HGRCPATH <<'EOF'
243 265 > [alias]
244 266 > printa = log -T "$A\n" -r 0
245 267 > EOF
246 268
247 269 $ A=1 hg --config pager.attend-printa=yes printa
248 270 paged! '1\n'
249 271 $ A=2 hg --config pager.attend-printa=yes printa
250 272 paged! '2\n'
251 273
252 274 Something that's explicitly attended is still not paginated if the
253 275 pager is globally set to off using a flag:
254 276 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
255 277 2
256 278
257 279 Pager should not override the exit code of other commands
258 280
259 281 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
260 282 > from mercurial import commands, registrar
261 283 > cmdtable = {}
262 284 > command = registrar.command(cmdtable)
263 285 > @command(b'fortytwo', [], b'fortytwo', norepo=True)
264 286 > def fortytwo(ui, *opts):
265 287 > ui.write(b'42\n')
266 288 > return 42
267 289 > EOF
268 290
269 291 $ cat >> $HGRCPATH <<'EOF'
270 292 > [extensions]
271 293 > fortytwo = $TESTTMP/fortytwo.py
272 294 > EOF
273 295
274 296 $ hg fortytwo --pager=on
275 297 paged! '42\n'
276 298 [42]
277 299
278 300 A command that asks for paging using ui.pager() directly works:
279 301 $ hg blame a
280 302 paged! ' 0: a\n'
281 303 paged! ' 1: a 1\n'
282 304 paged! ' 2: a 2\n'
283 305 paged! ' 3: a 3\n'
284 306 paged! ' 4: a 4\n'
285 307 paged! ' 5: a 5\n'
286 308 paged! ' 6: a 6\n'
287 309 paged! ' 7: a 7\n'
288 310 paged! ' 8: a 8\n'
289 311 paged! ' 9: a 9\n'
290 312 paged! '10: a 10\n'
291 313 but not with HGPLAIN
292 314 $ HGPLAIN=1 hg blame a
293 315 0: a
294 316 1: a 1
295 317 2: a 2
296 318 3: a 3
297 319 4: a 4
298 320 5: a 5
299 321 6: a 6
300 322 7: a 7
301 323 8: a 8
302 324 9: a 9
303 325 10: a 10
304 326 explicit flags work too:
305 327 $ hg blame --pager=no a
306 328 0: a
307 329 1: a 1
308 330 2: a 2
309 331 3: a 3
310 332 4: a 4
311 333 5: a 5
312 334 6: a 6
313 335 7: a 7
314 336 8: a 8
315 337 9: a 9
316 338 10: a 10
317 339
318 340 A command with --output option:
319 341
320 342 $ hg cat -r0 a
321 343 paged! 'a\n'
322 344 $ hg cat -r0 a --output=-
323 345 paged! 'a\n'
324 346 $ hg cat -r0 a --output=out
325 347
326 348 $ hg export -r0
327 349 paged! '# HG changeset patch\n'
328 350 paged! '# User test\n'
329 351 paged! '# Date 0 0\n'
330 352 paged! '# Thu Jan 01 00:00:00 1970 +0000\n'
331 353 paged! '# Node ID 1f0dee641bb7258c56bd60e93edfa2405381c41e\n'
332 354 paged! '# Parent 0000000000000000000000000000000000000000\n'
333 355 paged! 'add a\n'
334 356 paged! '\n'
335 357 paged! '\x1b[0;1mdiff -r 000000000000 -r 1f0dee641bb7 a\x1b[0m\n'
336 358 paged! '\x1b[0;31;1m--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
337 359 paged! '\x1b[0;32;1m+++ b/a\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
338 360 paged! '\x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m\n'
339 361 paged! '\x1b[0;32m+a\x1b[0m\n'
340 362 $ hg export -r0 -o -
341 363 paged! '# HG changeset patch\n'
342 364 paged! '# User test\n'
343 365 paged! '# Date 0 0\n'
344 366 paged! '# Thu Jan 01 00:00:00 1970 +0000\n'
345 367 paged! '# Node ID 1f0dee641bb7258c56bd60e93edfa2405381c41e\n'
346 368 paged! '# Parent 0000000000000000000000000000000000000000\n'
347 369 paged! 'add a\n'
348 370 paged! '\n'
349 371 paged! '\x1b[0;1mdiff -r 000000000000 -r 1f0dee641bb7 a\x1b[0m\n'
350 372 paged! '\x1b[0;31;1m--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
351 373 paged! '\x1b[0;32;1m+++ b/a\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
352 374 paged! '\x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m\n'
353 375 paged! '\x1b[0;32m+a\x1b[0m\n'
354 376 $ hg export -r0 -o out
355 377
356 378 $ rm out
357 379
358 380 Put annotate in the ignore list for pager:
359 381 $ cat >> $HGRCPATH <<EOF
360 382 > [pager]
361 383 > ignore = annotate
362 384 > EOF
363 385 $ hg blame a
364 386 0: a
365 387 1: a 1
366 388 2: a 2
367 389 3: a 3
368 390 4: a 4
369 391 5: a 5
370 392 6: a 6
371 393 7: a 7
372 394 8: a 8
373 395 9: a 9
374 396 10: a 10
375 397
376 398 During pushbuffer, pager should not start:
377 399 $ cat > $TESTTMP/pushbufferpager.py <<EOF
378 400 > def uisetup(ui):
379 401 > ui.pushbuffer()
380 402 > ui.pager(b'mycmd')
381 403 > ui.write(b'content\n')
382 404 > ui.write(ui.popbuffer())
383 405 > EOF
384 406
385 407 $ echo append >> a
386 408 $ hg --config extensions.pushbuffer=$TESTTMP/pushbufferpager.py status --color=off
387 409 content
388 410 paged! 'M a\n'
389 411
390 412 Environment variables like LESS and LV are set automatically:
391 413 $ cat > $TESTTMP/printlesslv.py <<EOF
392 414 > from __future__ import absolute_import
393 415 > import os
394 416 > import sys
395 417 > sys.stdin.read()
396 418 > for name in ['LESS', 'LV']:
397 419 > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-')))
398 420 > sys.stdout.flush()
399 421 > EOF
400 422
401 423 $ cat >> $HGRCPATH <<EOF
402 424 > [alias]
403 425 > noop = log -r 0 -T ''
404 426 > [ui]
405 427 > formatted=1
406 428 > [pager]
407 429 > pager = "$PYTHON" $TESTTMP/printlesslv.py
408 430 > EOF
409 431 $ unset LESS
410 432 $ unset LV
411 433 $ hg noop --pager=on
412 434 LESS=FRX
413 435 LV=-c
414 436 $ LESS=EFGH hg noop --pager=on
415 437 LESS=EFGH
416 438 LV=-c
General Comments 0
You need to be logged in to leave comments. Login now