~ubuntu-branches/ubuntu/lucid/mercurial/lucid

« back to all changes in this revision

Viewing changes to hgext/pager.py

  • Committer: Bazaar Package Importer
  • Author(s): Vernon Tang
  • Date: 2009-01-18 10:39:58 UTC
  • mfrom: (8.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090118103958-4ep2fqb5nl2pyc7y
Tags: 1.1.2-2
* debian/mercurial.postinst: symlink /usr/share/doc/mercurial if dpkg didn't
  do it when upgrading (closes: #512155)
* debian/control: mercurial-common replaces all earlier versions of
  mercurial

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#   [extension]
11
11
#   hgext.pager =
12
12
#
13
 
# To set the pager that should be used, set the application variable:
14
 
#
15
 
#   [pager]
16
 
#   pager = LESS='FSRX' less
17
 
#
18
 
# If no pager is set, the pager extensions uses the environment
19
 
# variable $PAGER. If neither pager.pager, nor $PAGER is set, no pager
20
 
# is used.
21
 
#
22
 
# If you notice "BROKEN PIPE" error messages, you can disable them
23
 
# by setting:
24
 
#
25
 
#   [pager]
26
 
#   quiet = True
 
13
# Run "hg help pager" to get info on configuration.
 
14
 
 
15
'''browse command output with external pager
 
16
 
 
17
To set the pager that should be used, set the application variable:
 
18
 
 
19
  [pager]
 
20
  pager = LESS='FSRX' less
 
21
 
 
22
If no pager is set, the pager extensions uses the environment
 
23
variable $PAGER. If neither pager.pager, nor $PAGER is set, no pager
 
24
is used.
 
25
 
 
26
If you notice "BROKEN PIPE" error messages, you can disable them
 
27
by setting:
 
28
 
 
29
  [pager]
 
30
  quiet = True
 
31
 
 
32
You can disable the pager for certain commands by adding them to the
 
33
pager.ignore list:
 
34
 
 
35
  [pager]
 
36
  ignore = version, help, update
 
37
 
 
38
You can also enable the pager only for certain commands using pager.attend:
 
39
 
 
40
  [pager]
 
41
  attend = log
 
42
 
 
43
If pager.attend is present, pager.ignore will be ignored.
 
44
 
 
45
To ignore global commands like "hg version" or "hg help", you have to specify
 
46
them in the global .hgrc
 
47
'''
27
48
 
28
49
import sys, os, signal
 
50
from mercurial import dispatch, util, extensions
29
51
 
30
52
def uisetup(ui):
31
 
    p = ui.config("pager", "pager", os.environ.get("PAGER"))
32
 
    if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
33
 
        if ui.configbool('pager', 'quiet'):
34
 
            signal.signal(signal.SIGPIPE, signal.SIG_DFL)
35
 
        sys.stderr = sys.stdout = os.popen(p, "wb")
 
53
    def pagecmd(orig, ui, options, cmd, cmdfunc):
 
54
        p = ui.config("pager", "pager", os.environ.get("PAGER"))
 
55
        if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
 
56
            attend = ui.configlist('pager', 'attend')
 
57
            if (cmd in attend or
 
58
                (cmd not in ui.configlist('pager', 'ignore') and not attend)):
 
59
                sys.stderr = sys.stdout = util.popen(p, "wb")
 
60
                if ui.configbool('pager', 'quiet'):
 
61
                    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
 
62
        return orig(ui, options, cmd, cmdfunc)
 
63
 
 
64
    extensions.wrapfunction(dispatch, '_runcommand', pagecmd)