spinner

The Spinner class creates an animated spinner indicator in the terminal. It supports multiple built-in styles and custom frames with configurable intervals.

Constructor

new Spinner(options?: SpinnerOptions)

Parameters

  • options: An optional SpinnerOptions object:
    • style: A SpinnerStyle preset — "dots", "line", "bounce", "arrow", or "moon". Defaults to "dots".
    • frames: Custom array of frame strings (overrides style preset).
    • interval: Milliseconds between frames. Defaults to 100.

Methods

  • start(silent?: boolean): Starts the spinner animation. When silent is true, only cycles frames internally without writing to stdout.
  • stop(): Stops the spinner and clears its output.
  • getCurrentFrame(): Returns the current spinner frame string.

Built-in Styles

  • "dots": ⣾ ⣷ ⣯ ⣟ ⣻ ⣽
  • "line": - \ | /
  • "bounce": ⠁ ⠂ ⠄ ⠂
  • "arrow": ← ↖ ↑ ↗ → ↘ ↓ ↙
  • "moon": 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘

Usage

import { Spinner } from "ts-better-console";

const spinner = new Spinner({ style: "dots" });
spinner.start();

// Stop after 3 seconds
setTimeout(() => spinner.stop(), 3000);

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!