Install chalk-animation
masterYou can install chalk-animation as a project dependency using npm:
$ npm i chalk-animationrepository·master·Indexed 24 days ago
https://github.com/bokub/chalk-animationA library for creating colorful, animated text output in terminal environments. It provides pre-defined animation styles including rainbow, pulse, glitch, radar, neon, and karaoke. Features include playback control via start() and stop(), text updates with replace(), and a CLI for running animations directly from the terminal. Version 2.0.3.
You can install chalk-animation as a project dependency using npm:
$ npm i chalk-animationchalk-animation package monkey-patches the standard console methods (log, info, warn, and error). If an animation is currently running, calling any of these console methods will automatically call .stop() on the active animation before printing the new message. This prevents animations from overwriting new log output in the terminal.Import chalkAnimation and call one of the animation methods (like rainbow, pulse, glitch, radar, neon, or karaoke) passing the text you want to animate. Animations start automatically upon creation.
import chalkAnimation from 'chalk-animation';
chalkAnimation.rainbow('Lorem ipsum dolor sit amet');If you want to control exactly when frames are displayed, call .stop() immediately after creation. You can then use .render() to display a frame or .frame() to retrieve the content of the next frame as a string.
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);To change the text being animated without creating a new instance, use the .replace(newText) method.
let str = 'Loading...';
const rainbow = chalkAnimation.rainbow(str);
// Add a new dot every second
setInterval(() => {
rainbow.replace(str += '.');
}, 1000);The animation instance returned by the animation method allows you to pause and resume playback using .stop() and .start().
const rainbow = chalkAnimation.rainbow('Lorem ipsum'); // Animation starts
setTimeout(() => {
rainbow.stop(); // Animation stops
}, 1000);
setTimeout(() => {
rainbow.start(); // Animation resumes
}, 2000);Pass a second parameter to the animation method to adjust the speed. The value should be a number greater than 0; the default is 1. A higher number results in a faster animation.
chalkAnimation.rainbow('Lorem ipsum', 2); // Two times faster than defaultThe following animation styles are available:
rainbowpulseglitchradarneonkaraokeIf installed globally, you can run animations directly from your terminal using the chalk-animation command.
Usage:
$ chalk-animation <name> [options] [text...]
Options:
--duration: Duration of the animation in ms (defaults to Infinity)--speed: Animation speed as a number > 0 (defaults to 1)Example:
$ chalk-animation rainbow Hello world!
# Install package globally
$ npm install --global chalk-animation
# Run an animation
$ chalk-animation rainbow Hello world!When you call an animation method (like rainbow() or glitch()), it returns an animation object. You can use this object to manipulate the running animation:
.stop(): Stops the animation..start(): Restarts the animation..replace(str): Updates the text being animated with a new string.Note: Calling a new animation method will automatically stop the previously running animation to prevent terminal overlapping.
The chalk-animation package provides several animated text effects that can be rendered to the terminal. Each animation method returns an animation object that allows you to control the playback.
Available animation methods:
rainbow(str, speed): A shifting rainbow gradient.pulse(str, speed): A red and white pulsing effect.glitch(str, speed): A chaotic glitch/distortion effect.radar(str, speed): A scanning shade effect.neon(str, speed): A flashing neon color effect.karaoke(str, speed): A color-fill effect that moves through the text.All methods accept a speed parameter (a number greater than 0) to control the playback rate.
rainbow.