20 lines
483 B
JavaScript
Raw Normal View History

const readline = require('readline');
2017-01-17 13:40:59 +01:00
/**
* Adds an animated progress indicator
*
* @param {string} message The message to write next to the indicator
2017-01-17 13:40:59 +01:00
*/
const animateProgress = (message) => {
const amountOfDots = 3;
let i = 0;
return setInterval(() => {
2017-01-17 13:40:59 +01:00
readline.cursorTo(process.stdout, 0);
i = (i + 1) % (amountOfDots + 1);
const dots = new Array(i + 1).join('.');
2017-01-17 13:40:59 +01:00
process.stdout.write(message + dots);
}, 500);
};
2017-01-17 13:40:59 +01:00
module.exports = animateProgress;