a size-intelligent progress bar?

Steven Taschuk staschuk at telusplanet.net
Wed Apr 9 23:01:22 EDT 2003


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.

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.

-- 
Steven Taschuk             "The world will end if you get this wrong."
staschuk at telusplanet.net     -- "Typesetting Mathematics -- User's Guide",
                                 Brian Kernighan and Lorrinda Cherry





More information about the Python-list mailing list