##// END OF EJS Templates
pager: respect HGPLAIN...
Yuya Nishihara -
r11414:0fa4474b default
parent child Browse files
Show More
@@ -1,96 +1,99
1 # pager.py - display output using a pager
1 # pager.py - display output using a pager
2 #
2 #
3 # Copyright 2008 David Soria Parra <dsp@php.net>
3 # Copyright 2008 David Soria Parra <dsp@php.net>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 #
7 #
8 # To load the extension, add it to your .hgrc file:
8 # To load the extension, add it to your .hgrc file:
9 #
9 #
10 # [extension]
10 # [extension]
11 # pager =
11 # pager =
12 #
12 #
13 # Run "hg help pager" to get info on configuration.
13 # Run "hg help pager" to get info on configuration.
14
14
15 '''browse command output with an external pager
15 '''browse command output with an external pager
16
16
17 To set the pager that should be used, set the application variable::
17 To set the pager that should be used, set the application variable::
18
18
19 [pager]
19 [pager]
20 pager = LESS='FSRX' less
20 pager = LESS='FSRX' less
21
21
22 If no pager is set, the pager extensions uses the environment variable
22 If no pager is set, the pager extensions uses the environment variable
23 $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used.
23 $PAGER. If neither pager.pager, nor $PAGER is set, no pager is used.
24
24
25 If you notice "BROKEN PIPE" error messages, you can disable them by
25 If you notice "BROKEN PIPE" error messages, you can disable them by
26 setting::
26 setting::
27
27
28 [pager]
28 [pager]
29 quiet = True
29 quiet = True
30
30
31 You can disable the pager for certain commands by adding them to the
31 You can disable the pager for certain commands by adding them to the
32 pager.ignore list::
32 pager.ignore list::
33
33
34 [pager]
34 [pager]
35 ignore = version, help, update
35 ignore = version, help, update
36
36
37 You can also enable the pager only for certain commands using
37 You can also enable the pager only for certain commands using
38 pager.attend. Below is the default list of commands to be paged::
38 pager.attend. Below is the default list of commands to be paged::
39
39
40 [pager]
40 [pager]
41 attend = annotate, cat, diff, export, glog, log, qdiff
41 attend = annotate, cat, diff, export, glog, log, qdiff
42
42
43 Setting pager.attend to an empty value will cause all commands to be
43 Setting pager.attend to an empty value will cause all commands to be
44 paged.
44 paged.
45
45
46 If pager.attend is present, pager.ignore will be ignored.
46 If pager.attend is present, pager.ignore will be ignored.
47
47
48 To ignore global commands like :hg:`version` or :hg:`help`, you have
48 To ignore global commands like :hg:`version` or :hg:`help`, you have
49 to specify them in the global .hgrc
49 to specify them in the global .hgrc
50 '''
50 '''
51
51
52 import sys, os, signal, shlex, errno
52 import sys, os, signal, shlex, errno
53 from mercurial import dispatch, util, extensions
53 from mercurial import dispatch, util, extensions
54
54
55 def _runpager(p):
55 def _runpager(p):
56 if not hasattr(os, 'fork'):
56 if not hasattr(os, 'fork'):
57 sys.stderr = sys.stdout = util.popen(p, 'wb')
57 sys.stderr = sys.stdout = util.popen(p, 'wb')
58 return
58 return
59 fdin, fdout = os.pipe()
59 fdin, fdout = os.pipe()
60 pid = os.fork()
60 pid = os.fork()
61 if pid == 0:
61 if pid == 0:
62 os.close(fdin)
62 os.close(fdin)
63 os.dup2(fdout, sys.stdout.fileno())
63 os.dup2(fdout, sys.stdout.fileno())
64 os.dup2(fdout, sys.stderr.fileno())
64 os.dup2(fdout, sys.stderr.fileno())
65 os.close(fdout)
65 os.close(fdout)
66 return
66 return
67 os.dup2(fdin, sys.stdin.fileno())
67 os.dup2(fdin, sys.stdin.fileno())
68 os.close(fdin)
68 os.close(fdin)
69 os.close(fdout)
69 os.close(fdout)
70 try:
70 try:
71 os.execvp('/bin/sh', ['/bin/sh', '-c', p])
71 os.execvp('/bin/sh', ['/bin/sh', '-c', p])
72 except OSError, e:
72 except OSError, e:
73 if e.errno == errno.ENOENT:
73 if e.errno == errno.ENOENT:
74 # no /bin/sh, try executing the pager directly
74 # no /bin/sh, try executing the pager directly
75 args = shlex.split(p)
75 args = shlex.split(p)
76 os.execvp(args[0], args)
76 os.execvp(args[0], args)
77 else:
77 else:
78 raise
78 raise
79
79
80 def uisetup(ui):
80 def uisetup(ui):
81 if ui.plain():
82 return
83
81 def pagecmd(orig, ui, options, cmd, cmdfunc):
84 def pagecmd(orig, ui, options, cmd, cmdfunc):
82 p = ui.config("pager", "pager", os.environ.get("PAGER"))
85 p = ui.config("pager", "pager", os.environ.get("PAGER"))
83 if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
86 if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
84 attend = ui.configlist('pager', 'attend', attended)
87 attend = ui.configlist('pager', 'attend', attended)
85 if (cmd in attend or
88 if (cmd in attend or
86 (cmd not in ui.configlist('pager', 'ignore') and not attend)):
89 (cmd not in ui.configlist('pager', 'ignore') and not attend)):
87 ui.setconfig('ui', 'formatted', ui.formatted())
90 ui.setconfig('ui', 'formatted', ui.formatted())
88 ui.setconfig('ui', 'interactive', False)
91 ui.setconfig('ui', 'interactive', False)
89 _runpager(p)
92 _runpager(p)
90 if ui.configbool('pager', 'quiet'):
93 if ui.configbool('pager', 'quiet'):
91 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
94 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
92 return orig(ui, options, cmd, cmdfunc)
95 return orig(ui, options, cmd, cmdfunc)
93
96
94 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
97 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
95
98
96 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
99 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
General Comments 0
You need to be logged in to leave comments. Login now