curses and refreshing problem

Carl Banks pavlovevidence at gmail.com
Sun Dec 14 13:14:45 EST 2008


On Dec 14, 5:52 am, Karlo Lozovina <_karlo_ at _mosor.net_> wrote:
> Carl Banks <pavlovevide... at gmail.com> wrote innews:69d2698a-6f44-4d85-adc3-1180ab158632 at r15g2000prd.googlegroups.com:
>
> > Unless you are referring to some wget screen mode I don't know about,
> > I suspect wget outputs its progress bar using carriage returns
> > without newlines.  If that's all you want, there is no need to use
> > curses.
>
> > Here is a little example program to illustrate:
>
> > import time, sys
> > for i in range(21):
> >     sys.stdout.write('\rProgress: [' + '='*i + ' '*(20-i) + ']')
> >     sys.stdout.flush()
> >     time.sleep(1)
> > sys.stdout.write("\nFinised!\n")
>
> Thanks, that's it! I just assumed wget uses curses for the progress bar,
> so the carriage return didn't even cross my mind ;).


Sure.  One other thing I'd like to point out is sometimes even if
carriage return is not sufficient, you can get a little better control
of the terminal by using escape sequences (quod Google).  The more
basic Xterm escape sequences work in pretty much any Unix-like
environment you'd see these days, some might even work on a Windows
terminal.  For example, print "\033[2J\033[H" probably clears your
screen and moves the cursor to top.


Carl Banks



More information about the Python-list mailing list