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