|
1 # pager.py - display output using a pager |
|
2 # |
|
3 # Copyright 2008 David Soria Parra <dsp@php.net> |
|
4 # |
|
5 # This software may be used and distributed according to the terms |
|
6 # of the GNU General Public License, incorporated herein by reference. |
|
7 # |
|
8 # To load the extension add it to your .hgrc file |
|
9 # |
|
10 # [extension] |
|
11 # hgext.pager = |
|
12 # |
|
13 # To set the pager that should be used, set the application variable |
|
14 # |
|
15 # [pager] |
|
16 # application = less |
|
17 # |
|
18 # You can also set environment variables there |
|
19 # |
|
20 # [pager] |
|
21 # application = LESS='FSRX' less |
|
22 # |
|
23 # If no application is set, the pager extensions use the environment |
|
24 # variable $PAGER. If neither pager.application, nor |
|
25 # $PAGER is set, no pager is used. |
|
26 # |
|
27 # If you notice "BROKEN PIPE" error messages, you can disable them |
|
28 # by setting |
|
29 # |
|
30 # [pager] |
|
31 # quiet = True |
|
32 # |
|
33 |
|
34 import sys, os, signal |
|
35 |
|
36 def getpager(ui): |
|
37 '''return a pager |
|
38 |
|
39 We separate this method from the pager class as we don't want to |
|
40 instantiate a pager if it is not used at all |
|
41 ''' |
|
42 if sys.stdout.isatty(): |
|
43 return (ui.config("pager", "application") |
|
44 or os.environ.get("PAGER")) |
|
45 |
|
46 def uisetup(ui): |
|
47 # disable broken pipe error messages |
|
48 if ui.configbool('pager', 'quiet', False): |
|
49 signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
|
50 |
|
51 if getpager(ui): |
|
52 pager = os.popen(getpager(ui), 'wb') |
|
53 sys.stderr = pager |
|
54 sys.stdout = pager |