[PATCH] RFC hgext/pager: disable pager when things happen
Mads Kiilerich
mads at kiilerich.com
Tue Oct 21 17:25:35 CDT 2008
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1224627926 -7200
# Node ID 998c0d4852e6dc30eaa89e50bb35902d48cf40a8
# Parent 71d6a2187ce6d0cb8e2c7b030530f347ddbbef3e
RFC hgext/pager: disable pager when things happen
This seems to work better-than-before for me. At least for the email command.
Especially combined with [pager] pager=less --quit-if-one-screen
Is it working for you? Could or should it be improved by monkey-wrapping other
functions? Is it worth improving?
diff -r 71d6a2187ce6 -r 998c0d4852e6 hgext/pager.py
--- a/hgext/pager.py Sun Oct 19 21:15:32 2008 +0200
+++ b/hgext/pager.py Wed Oct 22 00:25:26 2008 +0200
@@ -29,6 +29,9 @@
[pager]
quiet = True
+Some interactive commands will be detected automatically and disable the pager
+for the rest of this command.
+
You can disable the pager for certain commands by adding them to the
pager.ignore list:
@@ -48,6 +51,9 @@
import sys, os, signal
from mercurial import dispatch, util
+from mercurial.i18n import _
+
+wrapped_sys_stderrout = None
def uisetup(ui):
def pagecmd(ui, options, cmd, cmdfunc):
@@ -56,6 +62,8 @@
attend = ui.configlist('pager', 'attend')
if (cmd in attend or
(cmd not in ui.configlist('pager', 'ignore') and not attend)):
+ global wrapped_sys_stderrout
+ wrapped_sys_stderrout = (sys.stderr, sys.stdout)
sys.stderr = sys.stdout = util.popen(p, "wb")
if ui.configbool('pager', 'quiet'):
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
@@ -63,3 +71,14 @@
oldrun = dispatch._runcommand
dispatch._runcommand = pagecmd
+
+ def disable_pager_wrapper(wrapped, *args, **kwargs):
+ global wrapped_sys_stderrout
+ if wrapped_sys_stderrout:
+ sys.stdout.close() # closing the pager pipe FIXME: is this needed or a good idea?
+ (sys.stderr, sys.stdout) = wrapped_sys_stderrout # FIXME: what if we have been hooked too?
+ wrapped_sys_stderrout = None
+ ui.debug(_('pager disabled by %s\n') % wrapped.__name__)
+ return wrapped(*args, **kwargs)
+ ui__class__prompt = ui.__class__.prompt
+ ui.__class__.prompt = lambda *args, **kwargs: disable_pager_wrapper(ui__class__prompt, *args, **kwargs)
More information about the Mercurial-devel
mailing list