[PATCH] pager: Add a configuration to enable/disable the pager for certain commands
Matt Mackall
mpm at selenic.com
Sat Mar 29 13:18:21 CDT 2008
On Sat, 2008-03-29 at 18:04 +0100, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <dsp at php.net>
> # Date 1206810117 -3600
> # Node ID 0fcf2f1eb30329c9c35588cbe545898caf2141e3
> # Parent d1cf40b596f8c175d87c874f060ac5d4e4e74939
> pager: Add a configuration to enable/disable the pager for certain commands
>
> Add the configuration options pager.ignore and pager.attend.
> You can disable the pager on certain commands by adding them to the
> pager.ignore setting. To whitelist commands, you can add them to pager.attend.
> To disable or enable global commands like 'hg version' or 'hg help'
> you have to use your global .hgrc.
>
> diff -r d1cf40b596f8 -r 0fcf2f1eb303 hgext/pager.py
> --- a/hgext/pager.py Sat Mar 29 17:27:35 2008 +0100
> +++ b/hgext/pager.py Sat Mar 29 18:01:57 2008 +0100
> @@ -24,12 +24,39 @@
> #
> # [pager]
> # quiet = True
> +#
> +# You can disable the pager for certain commands by adding them to the
> +# pager.ignore list:
> +#
> +# [pager]
> +# ignore = version, help, update
> +#
> +# You can also enable the pager only for certain commands using pager.attend:
> +#
> +# [pager]
> +# attend = log
> +#
> +# If pager.attend is present, pager.ignore will be ignored.
> +#
> +# To ignore global commands like 'hg version' or 'hg help', you have to specify them
> +# in the global .hgrc.
> +#
>
> import sys, os, signal
> +from mercurial import dispatch
> +
> +def _runcommand(func, pager):
> + def ignore(ui, options, cmd, cmdfunc):
> + include = ui.configlist('pager', 'attend')
> + exclude = ui.configlist('pager', 'ignore')
> + if include.count(cmd) > 0 or (exclude.count(cmd) == 0 and not include):
> + sys.stderr = sys.stdout = os.popen(pager, "wb")
> + func(ui, options, cmd, cmdfunc)
> + return ignore
>
> def uisetup(ui):
> p = ui.config("pager", "pager", os.environ.get("PAGER"))
> if p and sys.stdout.isatty():
> if ui.configbool('pager', 'quiet'):
> signal.signal(signal.SIGPIPE, signal.SIG_DFL)
> - sys.stderr = sys.stdout = os.popen(p, "wb")
> + dispatch._runcommand = _runcommand(dispatch._runcommand, p)
- there's no need for a separate _runcommand function
- it's preferable not to assign ui.config calls to variables unless
you're going to use them more than once
- there's better ways to search a list
I simplified your code to:
def uisetup(ui):
def pagecmd(ui, options, cmd, cmdfunc):
p = ui.config("pager", "pager", os.environ.get("PAGER"))
if p and sys.stdout.isatty():
if (cmd in ui.configlist('pager', 'attend') or
cmd not in ui.configlist('pager', 'ignore')):
sys.stderr = sys.stdout = os.popen(pager, "wb")
if ui.configbool('pager', 'quiet'):
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
return oldrun(ui, options, cmd, cmdfunc)
oldrun = dispatch._runcommand
dispatch._runcommand = pagecmd
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list