Created
April 5, 2015 09:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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