a size-intelligent progress bar?

Michael Hudson mwh at python.net
Thu Apr 10 06:23:09 EDT 2003


Steven Taschuk <staschuk at telusplanet.net> writes:

> Quoth Tom Chance:
> > I'm making a shell-based program that includes a progress bar (like wget's
> > one). At the moment, I've got it printing an equals sign every 2% so I get
> > a progress bar 50 "="s wide, which fits my Konsole perfectly. This isn't
> > very handy for other shell sizes though :)
> > 
> > Does anyone have, or can anyone point me in the direction of a way of making
> > a decent progress bar that will automagically detect the width of the shell
> > open, even resizing it mid-"progress"?
> 
> I think the way to determine the width of the current terminal is
> terminal-dependent.  You could use curses.

Or check environment variables, or use ioctl.  I've posted code to do
this many, many times to this newsgroup, though not for a while.

> If memory serves, when a window gets resized the process(es?)
> associated with it gets sent a WINCH signal.  I don't know whether
> curses traps this for you; if so, just keep rechecking the
> terminal width via curses at appropriate moments.

Just checking the terminal size each time you redraw the progress bar
should be sufficient.

Cheers,
M.

-- 
  It is time-consuming to produce high-quality software. However,
  that should not alone be a reason to give up the high standards
  of Python development.              -- Martin von Loewis, python-dev




More information about the Python-list mailing list