Show More
@@ -1,367 +1,369 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 | An invalid pager command name is reported sensibly if we don't have to |
|
199 | 199 | use shell=True in the subprocess call: |
|
200 | 200 | $ hg log --limit 3 --config pager.pager=this-command-better-never-exist |
|
201 | 201 | missing pager command 'this-command-better-never-exist', skipping pager |
|
202 | 202 | \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc) |
|
203 | 203 | tag: tip |
|
204 | 204 | user: test |
|
205 | 205 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
206 | 206 | summary: modify a 10 |
|
207 | 207 | |
|
208 | 208 | \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc) |
|
209 | 209 | user: test |
|
210 | 210 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
211 | 211 | summary: modify a 9 |
|
212 | 212 | |
|
213 | 213 | \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc) |
|
214 | 214 | user: test |
|
215 | 215 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
216 | 216 | summary: modify a 8 |
|
217 | 217 | |
|
218 | 218 | |
|
219 | 219 | A complicated pager command gets worse behavior. Bonus points if you can |
|
220 | 220 | improve this. |
|
221 | 221 | $ hg log --limit 3 \ |
|
222 | 222 | > --config pager.pager='this-command-better-never-exist --seriously' \ |
|
223 | 223 | > 2>/dev/null || true |
|
224 | 224 | |
|
225 | 225 | Pager works with shell aliases. |
|
226 | 226 | |
|
227 | 227 | $ cat >> $HGRCPATH <<EOF |
|
228 | 228 | > [alias] |
|
229 | 229 | > echoa = !echo a |
|
230 | 230 | > EOF |
|
231 | 231 | |
|
232 | 232 | $ hg echoa |
|
233 | 233 | a |
|
234 | 234 | BROKEN: should be paged |
|
235 | 235 | $ hg --config pager.attend-echoa=yes echoa |
|
236 | 236 | a |
|
237 | 237 | |
|
238 | 238 | Pager works with hg aliases including environment variables. |
|
239 | 239 | |
|
240 | 240 | $ cat >> $HGRCPATH <<'EOF' |
|
241 | 241 | > [alias] |
|
242 | 242 | > printa = log -T "$A\n" -r 0 |
|
243 | 243 | > EOF |
|
244 | 244 | |
|
245 | 245 | $ A=1 hg --config pager.attend-printa=yes printa |
|
246 | 246 | paged! '1\n' |
|
247 | 247 | $ A=2 hg --config pager.attend-printa=yes printa |
|
248 | 248 | paged! '2\n' |
|
249 | 249 | |
|
250 | 250 | Something that's explicitly attended is still not paginated if the |
|
251 | 251 | pager is globally set to off using a flag: |
|
252 | 252 | $ A=2 hg --config pager.attend-printa=yes printa --pager=no |
|
253 | 253 | 2 |
|
254 | 254 | |
|
255 | 255 | Pager should not override the exit code of other commands |
|
256 | 256 | |
|
257 | 257 | $ cat >> $TESTTMP/fortytwo.py <<'EOF' |
|
258 | 258 | > from mercurial import commands, registrar |
|
259 | 259 | > cmdtable = {} |
|
260 | 260 | > command = registrar.command(cmdtable) |
|
261 | 261 | > @command(b'fortytwo', [], 'fortytwo', norepo=True) |
|
262 | 262 | > def fortytwo(ui, *opts): |
|
263 | 263 | > ui.write('42\n') |
|
264 | 264 | > return 42 |
|
265 | 265 | > EOF |
|
266 | 266 | |
|
267 | 267 | $ cat >> $HGRCPATH <<'EOF' |
|
268 | 268 | > [extensions] |
|
269 | 269 | > fortytwo = $TESTTMP/fortytwo.py |
|
270 | 270 | > EOF |
|
271 | 271 | |
|
272 | 272 | $ hg fortytwo --pager=on |
|
273 | 273 | paged! '42\n' |
|
274 | 274 | [42] |
|
275 | 275 | |
|
276 | 276 | A command that asks for paging using ui.pager() directly works: |
|
277 | 277 | $ hg blame a |
|
278 | 278 | paged! ' 0: a\n' |
|
279 | 279 | paged! ' 1: a 1\n' |
|
280 | 280 | paged! ' 2: a 2\n' |
|
281 | 281 | paged! ' 3: a 3\n' |
|
282 | 282 | paged! ' 4: a 4\n' |
|
283 | 283 | paged! ' 5: a 5\n' |
|
284 | 284 | paged! ' 6: a 6\n' |
|
285 | 285 | paged! ' 7: a 7\n' |
|
286 | 286 | paged! ' 8: a 8\n' |
|
287 | 287 | paged! ' 9: a 9\n' |
|
288 | 288 | paged! '10: a 10\n' |
|
289 | 289 | but not with HGPLAIN |
|
290 | 290 | $ HGPLAIN=1 hg blame a |
|
291 | 291 | 0: a |
|
292 | 292 | 1: a 1 |
|
293 | 293 | 2: a 2 |
|
294 | 294 | 3: a 3 |
|
295 | 295 | 4: a 4 |
|
296 | 296 | 5: a 5 |
|
297 | 297 | 6: a 6 |
|
298 | 298 | 7: a 7 |
|
299 | 299 | 8: a 8 |
|
300 | 300 | 9: a 9 |
|
301 | 301 | 10: a 10 |
|
302 | 302 | explicit flags work too: |
|
303 | 303 | $ hg blame --pager=no a |
|
304 | 304 | 0: a |
|
305 | 305 | 1: a 1 |
|
306 | 306 | 2: a 2 |
|
307 | 307 | 3: a 3 |
|
308 | 308 | 4: a 4 |
|
309 | 309 | 5: a 5 |
|
310 | 310 | 6: a 6 |
|
311 | 311 | 7: a 7 |
|
312 | 312 | 8: a 8 |
|
313 | 313 | 9: a 9 |
|
314 | 314 | 10: a 10 |
|
315 | 315 | |
|
316 | 316 | A command with --output option: |
|
317 | 317 | |
|
318 | 318 | $ hg cat -r0 a |
|
319 | 319 | paged! 'a\n' |
|
320 | 320 | $ hg cat -r0 a --output=- |
|
321 | 321 | paged! 'a\n' |
|
322 | 322 | $ hg cat -r0 a --output=out |
|
323 | 323 | $ rm out |
|
324 | 324 | |
|
325 | 325 | Put annotate in the ignore list for pager: |
|
326 | 326 | $ cat >> $HGRCPATH <<EOF |
|
327 | 327 | > [pager] |
|
328 | 328 | > ignore = annotate |
|
329 | 329 | > EOF |
|
330 | 330 | $ hg blame a |
|
331 | 331 | 0: a |
|
332 | 332 | 1: a 1 |
|
333 | 333 | 2: a 2 |
|
334 | 334 | 3: a 3 |
|
335 | 335 | 4: a 4 |
|
336 | 336 | 5: a 5 |
|
337 | 337 | 6: a 6 |
|
338 | 338 | 7: a 7 |
|
339 | 339 | 8: a 8 |
|
340 | 340 | 9: a 9 |
|
341 | 341 | 10: a 10 |
|
342 | 342 | |
|
343 | 343 | Environment variables like LESS and LV are set automatically: |
|
344 | 344 | $ cat > $TESTTMP/printlesslv.py <<EOF |
|
345 | > import os, sys | |
|
345 | > from __future__ import absolute_import | |
|
346 | > import os | |
|
347 | > import sys | |
|
346 | 348 | > sys.stdin.read() |
|
347 | 349 | > for name in ['LESS', 'LV']: |
|
348 | 350 | > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-'))) |
|
349 | 351 | > sys.stdout.flush() |
|
350 | 352 | > EOF |
|
351 | 353 | |
|
352 | 354 | $ cat >> $HGRCPATH <<EOF |
|
353 | 355 | > [alias] |
|
354 | 356 | > noop = log -r 0 -T '' |
|
355 | 357 | > [ui] |
|
356 | 358 | > formatted=1 |
|
357 | 359 | > [pager] |
|
358 | 360 | > pager = $PYTHON $TESTTMP/printlesslv.py |
|
359 | 361 | > EOF |
|
360 | 362 | $ unset LESS |
|
361 | 363 | $ unset LV |
|
362 | 364 | $ hg noop --pager=on |
|
363 | 365 | LESS=FRX |
|
364 | 366 | LV=-c |
|
365 | 367 | $ LESS=EFGH hg noop --pager=on |
|
366 | 368 | LESS=EFGH |
|
367 | 369 | LV=-c |
General Comments 0
You need to be logged in to leave comments.
Login now