[PATCH] pager: Add a configuration to enable/disable the pager for certain commands

David Soria Parra sn_ at gmx.net
Sat Mar 29 13:45:44 CDT 2008


Matt Mackall wrote:
> 
> - 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

Thanks a lot. Just my 50cent: we should only use pager.ignore if pager.attend is not set, otherwise
something like
 [pager]
 attend = log
will result in 'hg help' using a pager which is not desireable I guess (attend should whitelist
instead). So here is the updated patch:

# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1206816110 -3600
# Node ID e64d80916e8897d38778a271f5cd2c4e99de93ad
# 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. (thanks, Matt Mackall)

diff -r d1cf40b596f8 -r e64d80916e88 hgext/pager.py
--- a/hgext/pager.py	Sat Mar 29 17:27:35 2008 +0100
+++ b/hgext/pager.py	Sat Mar 29 19:41:50 2008 +0100
@@ -24,12 +24,37 @@
 #
 #   [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 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")
+    def pagecmd(ui, options, cmd, cmdfunc):
+        p = ui.config("pager", "pager", os.environ.get("PAGER"))
+        if p and sys.stdout.isatty():
+            attend = ui.configlist('pager', 'attend')
+            if (cmd in attend or
+                (cmd not in ui.configlist('pager', 'ignore') and not attend)):
+                sys.stderr = sys.stdout = os.popen(p, "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




More information about the Mercurial-devel mailing list