четверг, 8 августа 2019 г.

Node.js CLI Spinner

Файл spinner.js

function spinner () {
    var sequence = ['|', '/', '-', '\\'];
    var index = 0;
    var intervalId;
    return {
        start: function (doNotBlockNodeJsProcess) {
            index = 0;
            process.stdout.write(sequence[index]);
            intervalId = setInterval(function () {
                process.stdout.write(sequence[index].replace(/./g, '\b'));
                if (index < sequence.length - 1) {
                    index = index + 1;
                } else {
                    index = 0;
                }
                process.stdout.write(sequence[index]);
            }, 100);
           if (doNotBlockNodeJsProcess) {
                intervalId.unref();
           }
        },
        stop: function () {
            clearInterval(intervalId);
            process.stdout.write(sequence[index].replace(/./g, '\b'));
        }
    };
}

module.exports = spinner;

Файл index.js

var spinner = require('spinner')();

spinner.start(true);

setTimeout(function () {
     spinner.stop();
}, 5000);

1 комментарий:

  1. If you're trying hard to burn fat then you have to get on this brand new custom keto diet.

    To design this keto diet service, certified nutritionists, fitness couches, and professional cooks united to develop keto meal plans that are effective, suitable, economically-efficient, and delicious.

    Since their launch in 2019, thousands of people have already transformed their figure and health with the benefits a good keto diet can provide.

    Speaking of benefits; clicking this link, you'll discover 8 scientifically-confirmed ones given by the keto diet.

    ОтветитьУдалить