Mercurial > hg
annotate hgext/pager.py @ 24889:ab9390165429 stable
merge with i18n
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 30 Apr 2015 17:50:50 -0500 |
parents | 0baf41e02a4d |
children | 80c5b2666a96 |
rev | line source |
---|---|
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
1 # pager.py - display output using a pager |
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
2 # |
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
3 # Copyright 2008 David Soria Parra <dsp@php.net> |
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7995
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
7 # |
12083
ebfc46929f3e
help: refer to user configuration file more consistently
Brodie Rao <brodie@bitheap.org>
parents:
11414
diff
changeset
|
8 # To load the extension, add it to your configuration file: |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
9 # |
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
10 # [extension] |
10112
703db37d186b
hgext: enable extensions without "hgext." prefix in help texts
Martin Geisler <mg@lazybytes.net>
parents:
9841
diff
changeset
|
11 # pager = |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
12 # |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
13 # Run "hg help pager" to get info on configuration. |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
14 |
8894
868670dbc237
extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents:
8225
diff
changeset
|
15 '''browse command output with an external pager |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
16 |
9212
dfc1d5da98f0
pager: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents:
9069
diff
changeset
|
17 To set the pager that should be used, set the application variable:: |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
18 |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
19 [pager] |
17305
e66fa4d587dc
pager: drop -S option for less in example for pager configuration
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17250
diff
changeset
|
20 pager = less -FRX |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
21 |
9267
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
22 If no pager is set, the pager extensions uses the environment variable |
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
23 $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used. |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
24 |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
25 You can disable the pager for certain commands by adding them to the |
9212
dfc1d5da98f0
pager: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents:
9069
diff
changeset
|
26 pager.ignore list:: |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
27 |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
28 [pager] |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
29 ignore = version, help, update |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
30 |
9267
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
31 You can also enable the pager only for certain commands using |
9841
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
32 pager.attend. Below is the default list of commands to be paged:: |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
33 |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
34 [pager] |
9841
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
35 attend = annotate, cat, diff, export, glog, log, qdiff |
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
36 |
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
37 Setting pager.attend to an empty value will cause all commands to be |
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
38 paged. |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
39 |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
40 If pager.attend is present, pager.ignore will be ignored. |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
41 |
21281
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
42 Lastly, you can enable and disable paging for individual commands with |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
43 the attend-<command> option. This setting takes precedence over |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
44 existing attend and ignore options and defaults:: |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
45 |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
46 [pager] |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
47 attend-cat = false |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
48 |
10973
49a07f441496
Use hg role in help strings
Martin Geisler <mg@aragost.com>
parents:
10516
diff
changeset
|
49 To ignore global commands like :hg:`version` or :hg:`help`, you have |
12083
ebfc46929f3e
help: refer to user configuration file more consistently
Brodie Rao <brodie@bitheap.org>
parents:
11414
diff
changeset
|
50 to specify them in your user configuration file. |
12694
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
51 |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
52 The --pager=... option can also be used to control when the pager is |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
53 used. Use a boolean value like yes, no, on, off, or use auto for |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
54 normal behavior. |
21281
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
55 |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
56 ''' |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
57 |
18923
d2647edb1782
pager: add missing imports of errno and shlex
Bryan O'Sullivan <bryano@fb.com>
parents:
18717
diff
changeset
|
58 import atexit, sys, os, signal, subprocess, errno, shlex |
19940
7d99bff0f77c
pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents:
18923
diff
changeset
|
59 from mercurial import commands, dispatch, util, extensions, cmdutil |
12694
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
60 from mercurial.i18n import _ |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
61 |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16652
diff
changeset
|
62 testedwith = 'internal' |
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
16652
diff
changeset
|
63 |
17250
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
64 def _pagerfork(ui, p): |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
65 if not util.safehasattr(os, 'fork'): |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
66 sys.stdout = util.popen(p, 'wb') |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
67 if ui._isatty(sys.stderr): |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
68 sys.stderr = sys.stdout |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
69 return |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
70 fdin, fdout = os.pipe() |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
71 pid = os.fork() |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
72 if pid == 0: |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
73 os.close(fdin) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
74 os.dup2(fdout, sys.stdout.fileno()) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
75 if ui._isatty(sys.stderr): |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
76 os.dup2(fdout, sys.stderr.fileno()) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
77 os.close(fdout) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
78 return |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
79 os.dup2(fdin, sys.stdin.fileno()) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
80 os.close(fdin) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
81 os.close(fdout) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
82 try: |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
83 os.execvp('/bin/sh', ['/bin/sh', '-c', p]) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
84 except OSError, e: |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
85 if e.errno == errno.ENOENT: |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
86 # no /bin/sh, try executing the pager directly |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
87 args = shlex.split(p) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
88 os.execvp(args[0], args) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
89 else: |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
90 raise |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
91 |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
92 def _pagersubprocess(ui, p): |
16631
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
93 pager = subprocess.Popen(p, shell=True, bufsize=-1, |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
94 close_fds=util.closefds, stdin=subprocess.PIPE, |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
95 stdout=sys.stdout, stderr=sys.stderr) |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
96 |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
97 stdout = os.dup(sys.stdout.fileno()) |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
98 stderr = os.dup(sys.stderr.fileno()) |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
99 os.dup2(pager.stdin.fileno(), sys.stdout.fileno()) |
16752
359fda6cb01d
pager: use ui._isatty infrastructure
Matt Mackall <mpm@selenic.com>
parents:
16743
diff
changeset
|
100 if ui._isatty(sys.stderr): |
16631
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
101 os.dup2(pager.stdin.fileno(), sys.stderr.fileno()) |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
102 |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
103 @atexit.register |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
104 def killpager(): |
18717
fcc4b55876c3
pager: catch ctrl-c on exit (issue3834)
Matt Mackall <mpm@selenic.com>
parents:
17305
diff
changeset
|
105 if util.safehasattr(signal, "SIGINT"): |
fcc4b55876c3
pager: catch ctrl-c on exit (issue3834)
Matt Mackall <mpm@selenic.com>
parents:
17305
diff
changeset
|
106 signal.signal(signal.SIGINT, signal.SIG_IGN) |
16631
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
107 pager.stdin.close() |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
108 os.dup2(stdout, sys.stdout.fileno()) |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
109 os.dup2(stderr, sys.stderr.fileno()) |
369741ef7253
pager: preserve Hg's exit code (and fix Windows support) (issue3225)
Brodie Rao <brodie@sf.io>
parents:
14945
diff
changeset
|
110 pager.wait() |
11182
3c368a1c962d
pager: fork and exec pager as parent process
Brodie Rao <brodie@bitheap.org>
parents:
10516
diff
changeset
|
111 |
17250
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
112 def _runpager(ui, p): |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
113 # The subprocess module shipped with Python <= 2.4 is buggy (issue3533). |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
114 # The compat version is buggy on Windows (issue3225), but has been shipping |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
115 # with hg for a long time. Preserve existing functionality. |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
116 if sys.version_info >= (2, 5): |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
117 _pagersubprocess(ui, p) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
118 else: |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
119 _pagerfork(ui, p) |
18f935b4c05a
pager: work around bug in python 2.4's subprocess module (issue3533)
Michael Bacarella <mbacarella@janestreet.com>
parents:
16752
diff
changeset
|
120 |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
121 def uisetup(ui): |
16752
359fda6cb01d
pager: use ui._isatty infrastructure
Matt Mackall <mpm@selenic.com>
parents:
16743
diff
changeset
|
122 if '--debugger' in sys.argv or not ui.formatted(): |
11414 | 123 return |
124 | |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
6548
diff
changeset
|
125 def pagecmd(orig, ui, options, cmd, cmdfunc): |
6417
13fafd8cc4a1
pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents:
6324
diff
changeset
|
126 p = ui.config("pager", "pager", os.environ.get("PAGER")) |
21277
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
127 usepager = False |
21278
e1f5f38fd944
pager: break always out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21277
diff
changeset
|
128 always = util.parsebool(options['pager']) |
21279
19b8cfe4396f
pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21278
diff
changeset
|
129 auto = options['pager'] == 'auto' |
14515
76f295eaed86
util: add helper function isatty(fd) to check for tty-ness
Idan Kamara <idankk86@gmail.com>
parents:
13642
diff
changeset
|
130 |
21277
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
131 if not p: |
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
132 pass |
21278
e1f5f38fd944
pager: break always out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21277
diff
changeset
|
133 elif always: |
e1f5f38fd944
pager: break always out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21277
diff
changeset
|
134 usepager = True |
21279
19b8cfe4396f
pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21278
diff
changeset
|
135 elif not auto: |
19b8cfe4396f
pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21278
diff
changeset
|
136 usepager = False |
21277
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
137 else: |
9841
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
138 attend = ui.configlist('pager', 'attend', attended) |
21280 | 139 ignore = ui.configlist('pager', 'ignore') |
19940
7d99bff0f77c
pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents:
18923
diff
changeset
|
140 cmds, _ = cmdutil.findcmd(cmd, commands.table) |
7d99bff0f77c
pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents:
18923
diff
changeset
|
141 |
7d99bff0f77c
pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents:
18923
diff
changeset
|
142 for cmd in cmds: |
21281
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
143 var = 'attend-%s' % cmd |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
144 if ui.config('pager', var): |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
145 usepager = ui.configbool('pager', var) |
bcddddcf0b54
pager: add attend-<command> option
Matt Mackall <mpm@selenic.com>
parents:
21280
diff
changeset
|
146 break |
21279
19b8cfe4396f
pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21278
diff
changeset
|
147 if (cmd in attend or |
19b8cfe4396f
pager: break auto out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
21278
diff
changeset
|
148 (cmd not in ignore and not attend)): |
21277
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
149 usepager = True |
19940
7d99bff0f77c
pager: honour internal aliases
David Soria Parra <dsp@experimentalworks.net>
parents:
18923
diff
changeset
|
150 break |
21277
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
151 |
24066
afdf5f6ab37a
pager: set an attribute on ui indicating that a pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21281
diff
changeset
|
152 setattr(ui, 'pageractive', usepager) |
afdf5f6ab37a
pager: set an attribute on ui indicating that a pager is active
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21281
diff
changeset
|
153 |
21277
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
154 if usepager: |
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
155 ui.setconfig('ui', 'formatted', ui.formatted(), 'pager') |
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
156 ui.setconfig('ui', 'interactive', False, 'pager') |
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
157 if util.safehasattr(signal, "SIGPIPE"): |
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
158 signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
2bc778e2f9b3
pager: break pager invocation out of command check loop
Matt Mackall <mpm@selenic.com>
parents:
20790
diff
changeset
|
159 _runpager(ui, p) |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
6548
diff
changeset
|
160 return orig(ui, options, cmd, cmdfunc) |
6417
13fafd8cc4a1
pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents:
6324
diff
changeset
|
161 |
24067
0baf41e02a4d
pager: ensure wrapped dispatch._runcommand runs before color's
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24066
diff
changeset
|
162 # Wrap dispatch._runcommand after color is loaded so color can see |
0baf41e02a4d
pager: ensure wrapped dispatch._runcommand runs before color's
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24066
diff
changeset
|
163 # ui.pageractive. Otherwise, if we loaded first, color's wrapped |
0baf41e02a4d
pager: ensure wrapped dispatch._runcommand runs before color's
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24066
diff
changeset
|
164 # dispatch._runcommand would run without having access to ui.pageractive. |
0baf41e02a4d
pager: ensure wrapped dispatch._runcommand runs before color's
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24066
diff
changeset
|
165 def afterloaded(loaded): |
0baf41e02a4d
pager: ensure wrapped dispatch._runcommand runs before color's
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24066
diff
changeset
|
166 extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |
0baf41e02a4d
pager: ensure wrapped dispatch._runcommand runs before color's
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24066
diff
changeset
|
167 extensions.afterloaded('color', afterloaded) |
9841
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
168 |
12694
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
169 def extsetup(ui): |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
170 commands.globalopts.append( |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
171 ('', 'pager', 'auto', |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
172 _("when to paginate (boolean, always, auto, or never)"), |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
173 _('TYPE'))) |
04f6de46bf3a
pager: add global --pager=<auto/boolean> option
Brodie Rao <brodie@bitheap.org>
parents:
12083
diff
changeset
|
174 |
9841
7cd6dee6fe37
pager: provide a default attend list
Brodie Rao <me+hg@dackz.net>
parents:
9267
diff
changeset
|
175 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff'] |