
|
|
||||||||
Console_ProgressBarConsole_ProgressBar displays a customizable progress bar in the console/terminal.
Things to setup
Creating the barIn the example we create the progress bar instance with five parameters: The format string, bar string, empty string, console width and the target number. The first parameter, format string, defines the layout of the whole progress bar. It may contain any character and has some variables that get replaced:
The second argument is the string that is going to fill the progress bar. In the above example, the string "=>" was used. If the string you pass is too short (like "=>" in this example), the leftmost character is used to pad it to the needed size. If the string you pass is too long, excessive characters are stripped from the left. The third argument is the string that fills the "empty" space in the progress bar. In the above example, that would be "-". If the string you pass is too short (like "-" in this example), the rightmost character is used to pad it to the needed size. If the string you pass is too long, excessive characters are stripped from the right. The fourth argument specifies the width of the display. A normal console/terminal is 80 chars, so pass 80 here. Currently there is no method to determine the current width of a terminal. The fifth argument is the target number of the progress bar. For example, if you wanted to display a progress bar for a download of a file that is 115 KB big, you would pass 115 here. Updating and finishingAfter setting up the progress bar, you can start doing the real work - up- or downloading files, calculating something etc. Whenever you did a step forward, call update() with the current step number. When you're finished, you may want to remove the progress bar from screen - use erase() for this. |
|||||||||
| About the NetVisits, Inc Network | Advertise Developer Tutorials hosted by HostGator. Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy. |