Python Status Bar
Last Updated: 01/07/15
I had the recent need to create a robust status bar in Python. I ended up getting a bit carried away and added a bunch of features to it. The status bar currently supports the following:
- In place updating
- Dynamic lengths (bar length as well as total screen length)
- Support for completeness greater than 100%
- Auto-scaling within the min and max bar lengths if completeness exceeds 999%
- Dynamic increment size
- Custom styling
- Compatible with Windows and *NIX
I have licensed the code under the MIT license, so feel free to use it for whatever purpose you may have.
You can grab the full source code, here. If you run the provided example (python status_bar.py), it will show you how to use all of the features. The code is heavily commented, so you should be able to follow it, if not please ask for clarification. For those of you that only care about how the status bar can be updated inline, look at lines 162 – 166. All that is required is to write to stdout directly and use the carriage return character, ‘\r’, to reset to the beginning of the line. After that, the rest is up to you, as to how you wish to display the information.