A lightweight, no dependency, pluggable CLI spinner library.
npm i picospinner
import {Spinner} from 'picospinner';
const spinner = new Spinner('Loading...');
spinner.start();
setTimeout(() => {
spinner.succeed('Finished.');
}, 5000);
import {Spinner} from 'picospinner';
const spinner = new Spinner('Loading...', {
symbols: {
warn: 'โ '
}
});
spinner.start();
setTimeout(() => {
spinner.warn("Something didn't go quite right.");
}, 5000);
import {Spinner} from 'picospinner';
const spinner = new Spinner('Loading...', {
frames: ['-', '\\', '|', '/']
});
spinner.start();
setTimeout(() => {
spinner.info('Finished.');
}, 5000);
Calling spinner.stop();
will stop the spinner and remove it.
Colours can be achieved by using a formatter such as picocolors or chalk. First install picocolors:
npm i picocolors
Text can be formatted by passing pre-formatted text:
import {Spinner} from 'picospinner';
import pc from 'picocolors';
const spinner = new Spinner(pc.blue('Loading...'));
spinner.start();
setTimeout(() => spinner.setText(pc.magenta("Now it's magenta!")), 1000);
Symbols can be formatted by passing a symbol formatter.
import {Spinner} from 'picospinner';
import pc from 'picocolors';
const spinner = new Spinner({
text: pc.blue('Loading...'),
symbolFormatter: pc.green
});
spinner.start();
spinner.fail({
text: 'Disaster!',
symbolFormatter: pc.red
});
A custom tick speed (how often the spinner rotates) in milliseconds can be passed to spinner.start
:
import {Spinner} from 'picospinner';
const spinner = new Spinner();
spinner.start(10);