author | Martin Geisler <mg@lazybytes.net> |
Sun, 26 Jul 2009 01:56:02 +0200 | |
changeset 9267 | bd9e5d200186 |
parent 9212 | dfc1d5da98f0 |
child 9841 | 7cd6dee6fe37 |
permissions | -rw-r--r-- |
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 |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7995
diff
changeset
|
6 |
# GNU General Public License version 2, incorporated herein by reference. |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
7 |
# |
6324
ee1077b41d5c
pager: further simplify code, clean up comments
Matt Mackall <mpm@selenic.com>
parents:
6323
diff
changeset
|
8 |
# To load the extension, add it to your .hgrc 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] |
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
11 |
# hgext.pager = |
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] |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
20 |
pager = LESS='FSRX' less |
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 |
|
9267
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
25 |
If you notice "BROKEN PIPE" error messages, you can disable them by |
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
26 |
setting:: |
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 |
quiet = True |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
30 |
|
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
31 |
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
|
32 |
pager.ignore list:: |
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] |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
35 |
ignore = version, help, update |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
36 |
|
9267
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
37 |
You can also enable the pager only for certain commands using |
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
38 |
pager.attend:: |
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 |
[pager] |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
41 |
attend = log |
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
42 |
|
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
43 |
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
|
44 |
|
9267
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
45 |
To ignore global commands like "hg version" or "hg help", you have to |
bd9e5d200186
pager: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9212
diff
changeset
|
46 |
specify them in the global .hgrc |
6462
6c4e12682fb9
pager: make config info accessible with "hg help pager"
Christian Ebert <blacktrash@gmx.net>
parents:
6457
diff
changeset
|
47 |
''' |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
48 |
|
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
49 |
import sys, os, signal |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
6548
diff
changeset
|
50 |
from mercurial import dispatch, util, extensions |
6323
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
51 |
|
6e1308a09ffd
Use the pager given by the environment to display long output
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
52 |
def uisetup(ui): |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
6548
diff
changeset
|
53 |
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
|
54 |
p = ui.config("pager", "pager", os.environ.get("PAGER")) |
6457 | 55 |
if p and sys.stdout.isatty() and '--debugger' not in sys.argv: |
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
|
56 |
attend = ui.configlist('pager', 'attend') |
13fafd8cc4a1
pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents:
6324
diff
changeset
|
57 |
if (cmd in attend or |
13fafd8cc4a1
pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents:
6324
diff
changeset
|
58 |
(cmd not in ui.configlist('pager', 'ignore') and not attend)): |
6548
962eb403165b
replace usage of os.popen() with util.popen()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6462
diff
changeset
|
59 |
sys.stderr = sys.stdout = util.popen(p, "wb") |
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
|
60 |
if ui.configbool('pager', 'quiet'): |
13fafd8cc4a1
pager: Add a configuration to enable/disable the pager for certain commands
David Soria Parra <dsp <at> php.net>
parents:
6324
diff
changeset
|
61 |
signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
6548
diff
changeset
|
62 |
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
|
63 |
|
7216
292fb2ad2846
extensions: use new wrapper functions
Matt Mackall <mpm@selenic.com>
parents:
6548
diff
changeset
|
64 |
extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |