Skip to content

Instantly share code, notes, and snippets.

@fpinzn
Created April 5, 2015 09:04
Show Gist options
  • Save fpinzn/b7bf15db4433eecf457d to your computer and use it in GitHub Desktop.
Save fpinzn/b7bf15db4433eecf457d to your computer and use it in GitHub Desktop.
Progress bar for node that will use the whole width of the output buffer by default.
var ProgressBar = require('progress');
/*
`events` are for higher levels to call, `ticks` are progress bar marks.
an `event` can be a downloaded chunck of a file or an archived copied.
*/
var event2tickRatio, currentTickCount = 0, ticksMarked = 0;
// progress bar that occupies whole buffer window.
var pB = new ProgressBar(':bar', { total: process.stdout.columns });
module.exports = {
'setTicks': function(nTicks){
event2tickRatio = process.stdout.columns / nTicks;
},
'tick': function(){
currentTickCount++;
if(currentTickCount == event2tickRatio){
currentTickCount = 0;
ticksMarked++;
pB.tick();
}
},
'ticksMarked': ticksMarked
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment