Show More
@@ -1,69 +1,70 | |||
|
1 | 1 | # pager.py - display output using a pager |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2008 David Soria Parra <dsp@php.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | # |
|
8 | 8 | # To load the extension, add it to your .hgrc file: |
|
9 | 9 | # |
|
10 | 10 | # [extension] |
|
11 | 11 | # pager = |
|
12 | 12 | # |
|
13 | 13 | # Run "hg help pager" to get info on configuration. |
|
14 | 14 | |
|
15 | 15 | '''browse command output with an external pager |
|
16 | 16 | |
|
17 | 17 | To set the pager that should be used, set the application variable:: |
|
18 | 18 | |
|
19 | 19 | [pager] |
|
20 | 20 | pager = LESS='FSRX' less |
|
21 | 21 | |
|
22 | 22 | If no pager is set, the pager extensions uses the environment variable |
|
23 | 23 | $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used. |
|
24 | 24 | |
|
25 | 25 | If you notice "BROKEN PIPE" error messages, you can disable them by |
|
26 | 26 | setting:: |
|
27 | 27 | |
|
28 | 28 | [pager] |
|
29 | 29 | quiet = True |
|
30 | 30 | |
|
31 | 31 | You can disable the pager for certain commands by adding them to the |
|
32 | 32 | pager.ignore list:: |
|
33 | 33 | |
|
34 | 34 | [pager] |
|
35 | 35 | ignore = version, help, update |
|
36 | 36 | |
|
37 | 37 | You can also enable the pager only for certain commands using |
|
38 | 38 | pager.attend. Below is the default list of commands to be paged:: |
|
39 | 39 | |
|
40 | 40 | [pager] |
|
41 | 41 | attend = annotate, cat, diff, export, glog, log, qdiff |
|
42 | 42 | |
|
43 | 43 | Setting pager.attend to an empty value will cause all commands to be |
|
44 | 44 | paged. |
|
45 | 45 | |
|
46 | 46 | If pager.attend is present, pager.ignore will be ignored. |
|
47 | 47 | |
|
48 | 48 | To ignore global commands like "hg version" or "hg help", you have to |
|
49 | 49 | specify them in the global .hgrc |
|
50 | 50 | ''' |
|
51 | 51 | |
|
52 | 52 | import sys, os, signal |
|
53 | 53 | from mercurial import dispatch, util, extensions |
|
54 | 54 | |
|
55 | 55 | def uisetup(ui): |
|
56 | 56 | def pagecmd(orig, ui, options, cmd, cmdfunc): |
|
57 | 57 | p = ui.config("pager", "pager", os.environ.get("PAGER")) |
|
58 | 58 | if p and sys.stdout.isatty() and '--debugger' not in sys.argv: |
|
59 | 59 | attend = ui.configlist('pager', 'attend', attended) |
|
60 | 60 | if (cmd in attend or |
|
61 | 61 | (cmd not in ui.configlist('pager', 'ignore') and not attend)): |
|
62 | ui.setconfig('ui', 'interactive', False) | |
|
62 | 63 | sys.stderr = sys.stdout = util.popen(p, "wb") |
|
63 | 64 | if ui.configbool('pager', 'quiet'): |
|
64 | 65 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
|
65 | 66 | return orig(ui, options, cmd, cmdfunc) |
|
66 | 67 | |
|
67 | 68 | extensions.wrapfunction(dispatch, '_runcommand', pagecmd) |
|
68 | 69 | |
|
69 | 70 | attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff'] |
General Comments 0
You need to be logged in to leave comments.
Login now