Skip to content

Repository files navigation

Spinner

version Maintenance mit scorecard build

Run multiple CLI spinners at the same time. Each Spinner has its own text and state, while a shared renderer keeps active spinners aligned in the terminal.

Spinner animations come from cli-spinners. The API is inspired by Ora, with support for concurrent asynchronous work.

🚧 Requirements

💃 Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @topcli/spinner
# or
$ yarn add @topcli/spinner

👀 Usage example

Start each spinner independently, then wait for the work to settle:

import * as timers from "node:timers/promises";
import { Spinner } from "@topcli/spinner";

async function runTask(label, shouldFail = false) {
  const spinner = new Spinner().start(label);

  await timers.setTimeout(1_000);
  spinner.text = `${label}: still working`;
  await timers.setTimeout(1_000);

  if (shouldFail) {
    spinner.failed(`${label}: failed`);
  }
  else {
    spinner.succeed(`${label}: done in ${spinner.elapsedTime.toFixed(0)}ms`);
  }
}

await Promise.allSettled([
  runTask("Build"),
  runTask("Test"),
  runTask("Deploy", true)
]);

Tip

Set verbose: false to suppress spinner output when your CLI is used as an API.

📚 API

  • Spinner: create, update and settle one spinner.
  • computeWithSpinner: run an asynchronous operation with spinner lifecycle handling.

✨ Contributors

All Contributors

Thanks goes to these wonderful people (emoji key):

Gentilhomme
Gentilhomme

💻 📖 👀 🛡️ 🐛
Alexandre Malaj
Alexandre Malaj

💻 📖 🐛
PierreDemailly
PierreDemailly

💻 🚧
Ben
Ben

🐛
Clement Gombauld
Clement Gombauld

💻 👀

License

MIT

About

Elegant Asynchronous Terminal (CLI) Spinner for Node.js

Topics

Resources

Contributing

Security policy

Stars

49 stars

Watchers

3 watching

Forks

Releases

Used by

Contributors

Languages