CLI Spinners

3.4.0 · active · verified Wed Apr 22

cli-spinners is a JavaScript/TypeScript library that provides a comprehensive collection of over 70 distinct, pre-defined terminal spinners. Each spinner entry includes a recommended `interval` (in milliseconds) for frame display and an array of Unicode `frames` that constitute the animation sequence. The package's current stable version is 3.4.0, and it maintains an active release cadence, frequently adding new spinner designs. Its primary role is to serve as a data source for spinner animations, differentiating it from full-fledged terminal animation libraries like `ora`, which consume `cli-spinners`' data to render actual progress indicators. This design choice makes it highly flexible, as the underlying `spinners.json` file can be directly utilized in various environments and programming languages, with official ports existing for Python, Swift, Rust, Go, and Bash.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the default `cliSpinners` object and `randomSpinner`, retrieve spinner data, and provides a basic manual animation loop for illustrative purposes (though `ora` is recommended for actual terminal animation).

import cliSpinners, { randomSpinner, type Spinner } from 'cli-spinners';
import process from 'node:process';

// Get a specific spinner by name
const dotsSpinner: Spinner = cliSpinners.dots;
console.log('Using "dots" spinner (first frame):', dotsSpinner.frames[0]);

// Get a random spinner programmatically
const randSpinner: Spinner = randomSpinner();
console.log(`\nUsing a random spinner (first frame): ${randSpinner.frames[0]}...`);

// Example of manually animating a spinner (ora is recommended for production use)
let frameIndex = 0;
const spinnerName = 'dots';
const spinner = cliSpinners[spinnerName as keyof typeof cliSpinners]; // Access dynamically with type assertion
const interval = spinner.interval;
const frames = spinner.frames;

process.stdout.write(`\nAnimating "${spinnerName}": `);

const timer = setInterval(() => {
    process.stdout.write('\r'); // Clear the current line
    process.stdout.write(`Animating "${spinnerName}": ${frames[frameIndex]}`);
    frameIndex = (frameIndex + 1) % frames.length;
}, interval);

// Stop the animation after a few seconds
setTimeout(() => {
    clearInterval(timer);
    process.stdout.write('\r                                  \r'); // Clear the spinner line completely
    console.log(`\nStopped animating "${spinnerName}".`);
}, 3000);

view raw JSON →