Flexible ascii progress bar with 9 different head characters based on progress
$ npm install progress-softbarFirst 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.
var ProgressBar = require('progress-softbar');
var bar = new ProgressBar(':bar', { total: 10 });
var timer = setInterval(function () {
bar.tick();
if (bar.complete) {
console.log('\ncomplete\n');
clearInterval(timer);
}
}, 100);These are keys in the options object you can pass to the progress bar along with
total as seen in the example above.
currcurrent completed indextotaltotal number of ticks to completewidththe displayed width of the progress bar defaulting to totalstreamthe output stream defaulting to stderr (-headhead character defaulting to complete character now OBSOLETE for progress-softbar)completecompletion character defaulting to "="incompleteincomplete character defaulting to "-"renderThrottleminimum time between updates in milliseconds defaulting to 16clearoption to clear the bar on completion defaulting to falsecallbackoptional function to call when the progress bar completes
These are tokens you can use in the format of your progress bar.
:barthe progress bar itself:currentcurrent tick number:totaltotal ticks:elapsedtime elapsed in seconds:percentcompletion percentage:etaestimated completion time in seconds:raterate of ticks per second
You can define custom tokens by adding a {'name': value} object parameter to your method (tick(), update(), etc.) calls.
var bar = new ProgressBar(':current: :token1 :token2', { total: 3 })
bar.tick({
'token1': "Hello",
'token2': "World!\n"
})
bar.tick(2, {
'token1': "Goodbye",
'token2': "World!"
})The above example would result in the output below.
1: Hello World!
3: Goodbye World!
checking ▕██▏ ▏ 6% 233.9s
For more info see the original progress npm.
MIT