An annotated, single-line progress bar for terminals.
Project description
A simple way of providing an informative and clean progress bar on the terminal that:
- knows a terminal’s current width
- has a header
- works out of the box when reading files
- always shows a relative percentage
- a Microsoft progress bar pbar(100) # done del pbar # write the newline
To easily create a progress bar for reporting (reading) progress in a filehandle that can tell() its offset:
from progress_bar import InitBarForInfile pbar = InitBarForInfile("./README.rst") instream = open("./README.rst") for line in iter(instream.readline, ''): pbar(instream.tell()) del pbar
With those default arguments, the bar will be as wide as the terminal window. However, it will have two whitespaces on both sides of the bar to achieve a visually more appealing display. Terminal window width is defined by termios using fcntl, both from the standard library. The progress bar will be prefixed with the basename of the input file (“file.txt” in the above example).
Version History
- 8: README improvements thanks to Marc Abramowitz, @msabramo
- 7: fixed error with InitBar when no title is given
- 6: removed remaining function annotations (Py2.7; thanks to Adam Knight @ahknight)
--2014 Florian Leitner. All rights reserved.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.