progress
Flexible ascii progress bar.
Installation
Usage
First we create a ProgressBar
, giving it a format string as well as the total
, telling the progress bar when it will be considered complete. After that all we need to do is tick()
appropriately.
Options
These are keys in the options object you can pass to the progress bar along with total
as seen in the example above.
curr
current completed indextotal
total number of ticks to completewidth
the displayed width of the progress bar defaulting to totalstream
the output stream defaulting to stderrhead
head character defaulting to complete charactercomplete
completion character defaulting to "="incomplete
incomplete character defaulting to "-"renderThrottle
minimum time between updates in milliseconds defaulting to 16clear
option to clear the bar on completion defaulting to falsecallback
optional function to call when the progress bar completes
Tokens
These are tokens you can use in the format of your progress bar.
:bar
the progress bar itself:current
current tick number:total
total ticks:elapsed
time elapsed in seconds:percent
completion percentage:eta
estimated completion time in seconds:rate
rate of ticks per second
Custom Tokens
You can define custom tokens by adding a {'name': value}
object parameter to your method (tick()
, update()
, etc.) calls.
The above example would result in the output below.
Examples
Download
In our download example each tick has a variable influence, so we pass the chunk length which adjusts the progress bar appropriately relative to the total length.
The above example result in a progress bar like the one below.
Interrupt
To display a message during progress bar execution, use interrupt()
You can see more examples in the examples
folder.
License
MIT
Last updated