Awesome community module

chalk-animation

Build StatusnpmCodecovnpmXO code style

Colorful animations in terminal output

Available animations

Name Preview
rainbowrainbow
pulsepulse
glitchglitch
radarradar
neonneon
karaokekaraoke

Install

1
$ npm i chalk-animation

Usage

1 2 3
const chalkAnimation = require('chalk-animation'); chalkAnimation.rainbow('Lorem ipsum dolor sit amet');

Start and stop

You can stop and resume an animation with stop() and start() .

When created, the instance of chalkAnimation starts automatically .

1 2 3 4 5 6 7 8 9 10
const rainbow = chalkAnimation.rainbow('Lorem ipsum'); // Animation starts setTimeout(() => { rainbow.stop(); // Animation stops }, 1000); setTimeout(() => { rainbow.start(); // Animation resumes }, 2000);

Automatic stop

Anything printed to the console will stop the previous animation automatically

1 2 3 4 5
chalkAnimation.rainbow('Lorem ipsum'); setTimeout(() => { // Stop the 'Lorem ipsum' animation, then write on a new line. console.log('dolor sit amet'); }, 1000);

Changing speed

Change the animation speed using a second parameter. Should be greater than 0, default is 1.

1
chalkAnimation.rainbow('Lorem ipsum', 2); // Two times faster than default

Changing text

Change the animated text seamlessly with replace()

1 2 3 4 5 6 7
let str = 'Loading...'; const rainbow = chalkAnimation.rainbow(str); // Add a new dot every second setInterval(() => { rainbow.replace(str += '.'); }, 1000);

Manual rendering

Manually render frames with render() , or get the content of the next frame with frame()

1 2 3 4 5 6
const rainbow = chalkAnimation.rainbow('Lorem ipsum').stop(); // Don't start the animation rainbow.render(); // Display the first frame const frame = rainbow.frame(); // Get the second frame console.log(frame);

CLI mode

1 2
# Install package globally $ npm install --global chalk-animation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
$ chalk-animation --help Colorful animations in terminal output Usage $ chalk-animation <name> [options] [text...] Options --duration Duration of the animation in ms, defaults to Infinity --speed Animation speed as number > 0, defaults to 1 Available animations rainbow pulse glitch radar neon karaoke Example $ chalk-animation rainbow Hello world!

License

MIT © Boris K