[PATCH 2 of 2] pager: add global --paginate/--no-pager options

Augie Fackler durin42 at gmail.com
Sun Aug 22 13:11:30 CDT 2010


On Aug 22, 2010, at 11:24 AM, Brodie Rao wrote:

> On Aug 22, 2010, at 10:03 AM, Augie Fackler wrote:
> 
>> 
>> On Aug 21, 2010, at 10:17 PM, Brodie Rao wrote:
>> 
>>> # HG changeset patch
>>> # User Brodie Rao <brodie at bitheap.org>
>>> # Date 1282447030 14400
>>> # Node ID 3dff96bfd886be74c9c1c151a1ca76be0a133fc3
>>> # Parent  2f351b05d85db8e243156141398217bdf30f01c5
>>> pager: add global --paginate/--no-pager options
>>> 
>>> diff -r 2f351b05d85d -r 3dff96bfd886 hgext/pager.py
>>> --- a/hgext/pager.py	Sat Aug 21 23:11:35 2010 -0400
>>> +++ b/hgext/pager.py	Sat Aug 21 23:17:10 2010 -0400
>>> @@ -47,10 +47,14 @@ If pager.attend is present, pager.ignore
>>> 
>>> To ignore global commands like :hg:`version` or :hg:`help`, you have
>>> to specify them in the global .hgrc
>>> +
>>> +The --paginate and --no-pager options can also be used to control
>>> +when then pager is used.
>> 
>> Would it make sense for both of these flags to instead be a --pager flag which took never,always,auto much like the --color flag for the color extension?
> 
> I thought about that, but most programs that provide a --pager flag require to have an argument with the pager you want to use (e.g., --pager='less -foo -bar...'). Git has both --paginate and --no-pager that work the same way as in this patch.
> 
> I'm not opposed to making it --pager, though I think I'd rather it be --pager=<off,on,auto>. It wouldn't be consistent with --color but it'd be less to type.

Perhaps it could be --paginate=<off,never,on,always,auto> and leave the --pager flag free for changing the pager if desired? Or we could just assume people won't have a pager named one of those 5 things and overload the meaning, but that feels nasty to me somehow.

Any objection if I whip up a patch to let color take all 5 of those options for the --color flag?

> 
>>> '''
>>> 
>>> import sys, os, signal, shlex, errno
>>> -from mercurial import dispatch, util, extensions
>>> +from mercurial import commands, dispatch, util, extensions
>>> +from mercurial.i18n import _
>>> 
>>> def _runpager(p):
>>>   if not hasattr(os, 'fork'):
>>> @@ -83,9 +87,10 @@ def uisetup(ui):
>>> 
>>>   def pagecmd(orig, ui, options, cmd, cmdfunc):
>>>       p = ui.config("pager", "pager", os.environ.get("PAGER"))
>>> -        if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
>>> +        if (not options['no_pager'] and p and sys.stdout.isatty() and
>>> +            '--debugger' not in sys.argv):
>>>           attend = ui.configlist('pager', 'attend', attended)
>>> -            if (cmd in attend or
>>> +            if (options['paginate'] or cmd in attend or
>>>               (cmd not in ui.configlist('pager', 'ignore') and not attend)):
>>>               ui.setconfig('ui', 'formatted', ui.formatted())
>>>               ui.setconfig('ui', 'interactive', False)
>>> @@ -96,4 +101,9 @@ def uisetup(ui):
>>> 
>>>   extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
>>> 
>>> +commands.globalopts.extend([('', 'paginate', None,
>>> +                             _('enable paginated output')),
>>> +                            ('', 'no-pager', None,
>>> +                             _('disable paginated output'))])
>>> +
>>> attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']
>>> _______________________________________________
>>> Mercurial-devel mailing list
>>> Mercurial-devel at selenic.com
>>> http://selenic.com/mailman/listinfo/mercurial-devel
>> 
> 



More information about the Mercurial-devel mailing list