--- a/hgext/progress.py Mon Mar 29 16:11:40 2010 -0500
+++ b/hgext/progress.py Tue Mar 30 13:09:25 2010 -0500
@@ -33,6 +33,8 @@
# (that is, min(width, term width) will be used)
clear-complete = True # clear the progress bar after it's done
disable = False # if true, don't show a progress bar
+ assume-tty = False # if true, ALWAYS show a progress bar, unless
+ # disable is given
Valid entries for the format field are topic, bar, number, unit, and
item. item defaults to the last 20 characters of the item, but this
@@ -131,18 +133,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 +177,8 @@
# 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() or ui.configbool('progress', 'assume-tty'))
+ 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
--- a/mercurial/util.py Mon Mar 29 16:11:40 2010 -0500
+++ b/mercurial/util.py Tue Mar 30 13:09:25 2010 -0500
@@ -1260,7 +1260,7 @@
pass
try:
import termios, array, fcntl
- for dev in (sys.stdout, sys.stdin):
+ for dev in (sys.stderr, sys.stdout, sys.stdin):
try:
try:
fd = dev.fileno()
--- a/tests/test-progress Mon Mar 29 16:11:40 2010 -0500
+++ b/tests/test-progress Tue Mar 30 13:09:25 2010 -0500
@@ -31,30 +31,29 @@
echo "[extensions]" >> $HGRCPATH
echo "progress=" >> $HGRCPATH
echo "loop=`pwd`/loop.py" >> $HGRCPATH
-echo "[ui]" >> $HGRCPATH
-echo "interactive=1" >> $HGRCPATH
+echo "[progress]" >> $HGRCPATH
+echo "assume-tty=1" >> $HGRCPATH
echo '% test default params, display nothing because of delay'
-hg -y loop 3 | python filtercr.py
+hg -y loop 3 2>&1 | python filtercr.py
-echo "[progress]" >> $HGRCPATH
echo "delay=0" >> $HGRCPATH
echo "refresh=0" >> $HGRCPATH
echo '% test with delay=0, refresh=0'
-hg -y loop 3 | python filtercr.py
+hg -y loop 3 2>&1 | python filtercr.py
echo '% test refresh is taken in account'
-hg -y --config progress.refresh=100 loop 3 | python filtercr.py
+hg -y --config progress.refresh=100 loop 3 2>&1 | python filtercr.py
echo '% test format options 1'
-hg -y --config 'progress.format=number topic item+2' loop 2 | python filtercr.py
+hg -y --config 'progress.format=number topic item+2' loop 2 2>&1 | python filtercr.py
echo '% test format options 2'
-hg -y --config 'progress.format=number item-3 bar' loop 2 | python filtercr.py
+hg -y --config 'progress.format=number item-3 bar' loop 2 2>&1 | python filtercr.py
echo '% test format options and indeterminate progress'
-hg -y --config 'progress.format=number item bar' loop -- -2 | python filtercr.py
+hg -y --config 'progress.format=number item bar' loop -- -2 2>&1 | python filtercr.py
echo '% test immediate progress completion'
-hg -y loop 0 | python filtercr.py
+hg -y loop 0 2>&1 | python filtercr.py