hgext/pager.py
changeset 6457 7ef281e78c64
parent 6456 db5324d3c257
parent 6417 13fafd8cc4a1
child 6462 6c4e12682fb9
--- a/hgext/pager.py	Thu Apr 03 11:11:31 2008 +0200
+++ b/hgext/pager.py	Thu Apr 03 11:16:07 2008 +0200
@@ -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() and '--debugger' not in sys.argv:
-        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() and '--debugger' not in sys.argv:
+            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