react-deploy-progress v0.0.1
Flexible ascii progress bar.
Installation
$ npm install progressUsage
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.
var ProgressBar = require('progress');
var bar = new ProgressBar(':bar', { total: 10 });
var timer = setInterval(function () {
bar.tick();
if (bar.complete) {
console.log('\ncomplete\n');
clearInterval(timer);
}
}, 100);Options
These are keys in the options object you can pass to the progress bar along with
total as seen in the example above.
totaltotal number of ticks to completewidththe displayed width of the progress bar defaulting to totalstreamthe output stream defaulting to stderrcompletecompletion character defaulting to "="cursorlast completion character defaulting to completeincompleteincomplete 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
Tokens
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
Custom Tokens
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!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.
var ProgressBar = require('../');
var https = require('https');
var req = https.request({
host: 'download.github.com',
port: 443,
path: '/visionmedia-node-jscoverage-0d4608a.zip'
});
req.on('response', function(res){
var len = parseInt(res.headers['content-length'], 10);
console.log();
var bar = new ProgressBar(' downloading [:bar] :percent :etas', {
complete: '=',
cursor: '>',
incomplete: ' ',
width: 20,
total: len
});
res.on('data', function (chunk) {
bar.tick(chunk.length);
});
res.on('end', function () {
console.log('\n');
});
});
req.end();The above example result in a progress bar like the one below.
downloading [====> ] 29% 3.7sYou can see more examples in the examples folder.
License
MIT
8 years ago