Spinner

import { Spinner } from "jsr:@ende/cli/unstable-spinner";

class ยท experimental

class Spinner

A spinner that can be used to indicate that something is loading.

Example: Usage

import { Spinner } from "@ende/cli/unstable-spinner";

const spinner = new Spinner({ message: "Loading...", color: "yellow" });
spinner.start();

setTimeout(() => {
 spinner.stop();
 console.log("Finished loading!");
}, 3_000);

// You can also use the spinner with `Ende.stderr`
const spinner2 = new Spinner({ message: "Loading...", color: "yellow", output: Ende.stderr });
spinner2.start();

setTimeout(() => {
 spinner2.stop();
 console.error("Finished loading!");
}, 3_000);

Constructors

constructor

new Spinner(options?: SpinnerOptions)

Creates a new spinner.

options?: SpinnerOptions

Options for the spinner.

Properties

message

message: string

The message to display next to the spinner. This can be changed while the spinner is active.

Example: Usage

import { Spinner } from "@ende/cli/unstable-spinner";

const spinner = new Spinner({ message: "Working..." });
spinner.start();

for (let step = 0; step < 5; step++) {
  // do some work
  await new Promise((resolve) => setTimeout(resolve, 1000));

  spinner.message = `Finished Step #${step}`;
}

spinner.stop();
console.log("Done!");

Methods

color

set color(value: Color | undefined)

Set the color of the spinner. This defaults to the default terminal color. This can be changed while the spinner is active.

Providing undefined will use the default terminal color.

value: Color | undefined

Color to set.

Example: Usage

import { Spinner } from "@ende/cli/unstable-spinner";

const spinner = new Spinner({ message: "Loading...", color: "yellow" });
spinner.start();

// do some work
await new Promise((resolve) => setTimeout(resolve, 1000));

spinner.color = "magenta";
get color(): Color | undefined

Get the current color of the spinner.

Returns

The color of the spinner or undefined if it's using the terminal default.

Example: Usage

import { Spinner } from "@ende/cli/unstable-spinner";

const spinner = new Spinner({ message: "Loading", color: "blue" });

spinner.color; // Blue ANSI escape sequence

start

start(): void

Starts the spinner.

Example: Usage

import { Spinner } from "@ende/cli/unstable-spinner";

const spinner = new Spinner({ message: "Loading..." });
spinner.start();

stop

stop(): void

Stops the spinner.

Example: Usage

import { Spinner } from "@ende/cli/unstable-spinner";

const spinner = new Spinner({ message: "Loading..." });
spinner.start();

setTimeout(() => {
 spinner.stop();
 console.log("Finished loading!");
}, 3_000);

Source