[PATCH] progress: use stderr instead of stdin; check stderr.isatty()

Augie Fackler durin42 at gmail.com
Tue Mar 16 13:09:00 CDT 2010


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1268682717 18000
# Node ID 11ee2fee2200ae8c0d66b87de46d84399dc128da
# Parent  d8d1b56d451916f4da0a82c456ca397565924fcb
progress: use stderr instead of stdin; check stderr.isatty()


This means that progress bars will continue to show on the terminal
when both stdin and stdout are redirected.

diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -131,18 +131,18 @@
             out = spacejoin(head, prog, tail)
         else:
             out = spacejoin(head, tail)
-        sys.stdout.write('\r' + out[:termwidth])
-        sys.stdout.flush()
+        sys.stderr.write('\r' + out[:termwidth])
+        sys.stderr.flush()
 
     def clear(self):
-        sys.stdout.write('\r%s\r' % (' ' * self.width()))
+        sys.stderr.write('\r%s\r' % (' ' * self.width()))
 
     def complete(self):
         if self.ui.configbool('progress', 'clear-complete', default=True):
             self.clear()
         else:
-            sys.stdout.write('\n')
-        sys.stdout.flush()
+            sys.stderr.write('\n')
+        sys.stderr.flush()
 
     def width(self):
         tw = util.termwidth()
@@ -175,7 +175,7 @@
     # setconfig('progress', 'disable', 'True') to disable this extension
     if ui.configbool('progress', 'disable'):
         return
-    if ui.interactive() and not ui.debugflag and not ui.quiet:
+    if sys.stderr.isatty() and not ui.debugflag and not ui.quiet:
         # we instantiate one globally shared progress bar to avoid
         # competing progress bars when multiple UI objects get created
         global sharedprog


More information about the Mercurial-devel mailing list