[PATCH 1 of 2] pager: add global --pager=<auto/boolean> option

Brodie Rao brodie at bitheap.org
Sun Sep 19 10:59:07 CDT 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1284911506 18000
# Node ID 3ee6c8c332b6498af760708d1f7eb139c5f10edf
# Parent  d643ae555a4de42ca2798a43a48a7e7c2c729d0a
pager: add global --pager=<auto/boolean> option

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -47,10 +47,15 @@ If pager.attend is present, pager.ignore
 
 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 @@ def uisetup(ui):
         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,9 @@ def uisetup(ui):
 
     extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
 
+commands.globalopts.append(
+    ('', 'pager', 'auto',
+     _("when to paginate (boolean, always, auto, or never)"),
+     _('TYPE')))
+
 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']


More information about the Mercurial-devel mailing list