##// END OF EJS Templates
configitems: register the 'pager.attend' config
Boris Feld -
r34496:6d1b0970 default
parent child Browse files
Show More
@@ -1,73 +1,81 b''
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 configuration file:
8 # To load the extension, add it to your configuration 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 (DEPRECATED)
15 '''browse command output with an external pager (DEPRECATED)
16
16
17 Forcibly enable paging for individual commands that don't typically
17 Forcibly enable paging for individual commands that don't typically
18 request pagination with the attend-<command> option. This setting
18 request pagination with the attend-<command> option. This setting
19 takes precedence over ignore options and defaults::
19 takes precedence over ignore options and defaults::
20
20
21 [pager]
21 [pager]
22 attend-cat = false
22 attend-cat = false
23 '''
23 '''
24 from __future__ import absolute_import
24 from __future__ import absolute_import
25
25
26 from mercurial import (
26 from mercurial import (
27 cmdutil,
27 cmdutil,
28 commands,
28 commands,
29 dispatch,
29 dispatch,
30 extensions,
30 extensions,
31 registrar,
31 )
32 )
32
33
33 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
34 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
34 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
35 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
35 # be specifying the version(s) of Mercurial they are tested with, or
36 # be specifying the version(s) of Mercurial they are tested with, or
36 # leave the attribute unspecified.
37 # leave the attribute unspecified.
37 testedwith = 'ships-with-hg-core'
38 testedwith = 'ships-with-hg-core'
38
39
40 configtable = {}
41 configitem = registrar.configitem(configtable)
42
43 configitem('pager', 'attend',
44 default=lambda: attended,
45 )
46
39 def uisetup(ui):
47 def uisetup(ui):
40
48
41 def pagecmd(orig, ui, options, cmd, cmdfunc):
49 def pagecmd(orig, ui, options, cmd, cmdfunc):
42 auto = options['pager'] == 'auto'
50 auto = options['pager'] == 'auto'
43 if auto and not ui.pageractive:
51 if auto and not ui.pageractive:
44 usepager = False
52 usepager = False
45 attend = ui.configlist('pager', 'attend', attended)
53 attend = ui.configlist('pager', 'attend')
46 ignore = ui.configlist('pager', 'ignore')
54 ignore = ui.configlist('pager', 'ignore')
47 cmds, _ = cmdutil.findcmd(cmd, commands.table)
55 cmds, _ = cmdutil.findcmd(cmd, commands.table)
48
56
49 for cmd in cmds:
57 for cmd in cmds:
50 var = 'attend-%s' % cmd
58 var = 'attend-%s' % cmd
51 if ui.config('pager', var):
59 if ui.config('pager', var):
52 usepager = ui.configbool('pager', var)
60 usepager = ui.configbool('pager', var)
53 break
61 break
54 if (cmd in attend or
62 if (cmd in attend or
55 (cmd not in ignore and not attend)):
63 (cmd not in ignore and not attend)):
56 usepager = True
64 usepager = True
57 break
65 break
58
66
59 if usepager:
67 if usepager:
60 # Slight hack: the attend list is supposed to override
68 # Slight hack: the attend list is supposed to override
61 # the ignore list for the pager extension, but the
69 # the ignore list for the pager extension, but the
62 # core code doesn't know about attend, so we have to
70 # core code doesn't know about attend, so we have to
63 # lobotomize the ignore list so that the extension's
71 # lobotomize the ignore list so that the extension's
64 # behavior is preserved.
72 # behavior is preserved.
65 ui.setconfig('pager', 'ignore', '', 'pager')
73 ui.setconfig('pager', 'ignore', '', 'pager')
66 ui.pager('extension-via-attend-' + cmd)
74 ui.pager('extension-via-attend-' + cmd)
67 else:
75 else:
68 ui.disablepager()
76 ui.disablepager()
69 return orig(ui, options, cmd, cmdfunc)
77 return orig(ui, options, cmd, cmdfunc)
70
78
71 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
79 extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
72
80
73 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
81 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
General Comments 0
You need to be logged in to leave comments. Login now