2017-06-06 14:22:17 +02:00
|
|
|
const readline = require('readline');
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an animated progress indicator
|
|
|
|
*
|
2017-06-06 14:22:17 +02:00
|
|
|
* @param {string} message The message to write next to the indicator
|
2017-01-17 13:40:59 +01:00
|
|
|
*/
|
2017-06-06 14:22:17 +02: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);
|
2017-06-06 14:22:17 +02:00
|
|
|
const dots = new Array(i + 1).join('.');
|
2017-01-17 13:40:59 +01:00
|
|
|
process.stdout.write(message + dots);
|
|
|
|
}, 500);
|
2018-03-09 16:41:24 +01:00
|
|
|
};
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
module.exports = animateProgress;
|