@topcli/spinner
v5.0.0
Published
Asynchronous CLI Spinner. Allow to create and manage simultaneous/multiple spinners at a time.
Downloads
287,731
Readme
Spinner
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
- Node.js v22 or higher
💃 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: falseto 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
Thanks goes to these wonderful people (emoji key):
License
MIT
