diff hgext/pager.py @ 14515:76f295eaed86

util: add helper function isatty(fd) to check for tty-ness
author Idan Kamara <idankk86@gmail.com>
date Thu, 02 Jun 2011 00:43:34 +0300
parents 994510694b1d
children 11aad09a6370
line wrap: on
line diff
--- a/hgext/pager.py	Thu Jun 02 18:52:31 2011 +0800
+++ b/hgext/pager.py	Thu Jun 02 00:43:34 2011 +0300
@@ -60,7 +60,7 @@
 def _runpager(p):
     if not hasattr(os, 'fork'):
         sys.stdout = util.popen(p, 'wb')
-        if sys.stderr.isatty():
+        if util.isatty(sys.stderr):
             sys.stderr = sys.stdout
         return
     fdin, fdout = os.pipe()
@@ -68,7 +68,7 @@
     if pid == 0:
         os.close(fdin)
         os.dup2(fdout, sys.stdout.fileno())
-        if sys.stderr.isatty():
+        if util.isatty(sys.stderr):
             os.dup2(fdout, sys.stderr.fileno())
         os.close(fdout)
         return
@@ -86,12 +86,13 @@
             raise
 
 def uisetup(ui):
-    if ui.plain():
+    if ui.plain() or '--debugger' in sys.argv or not util.isatty(sys.stdout):
         return
 
     def pagecmd(orig, 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:
+
+        if p:
             attend = ui.configlist('pager', 'attend', attended)
             auto = options['pager'] == 'auto'
             always = util.parsebool(options['pager'])