changeset 12694:04f6de46bf3a

pager: add global --pager=<auto/boolean> option
author Brodie Rao <brodie@bitheap.org>
date Sun, 10 Oct 2010 12:21:48 -0500
parents 33f0682ba8b1
children 05077896ffe2
files hgext/pager.py
diffstat 1 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/pager.py	Sun Oct 10 12:21:36 2010 -0500
+++ b/hgext/pager.py	Sun Oct 10 12:21:48 2010 -0500
@@ -47,10 +47,15 @@
 
 To ignore global commands like :hg:`version` or :hg:`help`, you have
 to specify them in your user configuration file.
+
+The --pager=... option can also be used to control when the pager is
+used. Use a boolean value like yes, no, on, off, or use auto for
+normal behavior.
 '''
 
 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'):
@@ -85,8 +90,11 @@
         p = ui.config("pager", "pager", os.environ.get("PAGER"))
         if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
             attend = ui.configlist('pager', 'attend', attended)
-            if (cmd in attend or
-                (cmd not in ui.configlist('pager', 'ignore') and not attend)):
+            auto = options['pager'] == 'auto'
+            always = util.parsebool(options['pager'])
+            if (always or auto and
+                (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)
                 _runpager(p)
@@ -96,4 +104,10 @@
 
     extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
 
+def extsetup(ui):
+    commands.globalopts.append(
+        ('', 'pager', 'auto',
+         _("when to paginate (boolean, always, auto, or never)"),
+         _('TYPE')))
+
 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']