Spinner
import { Spinner } from "jsr:@ende/cli/unstable-spinner";class ยท experimental
class SpinnerA 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?: SpinnerOptionsOptions for the spinner.
Properties
message
message: stringThe 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 | undefinedColor 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 | undefinedGet 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(): voidStarts the spinner.
Example: Usage
import { Spinner } from "@ende/cli/unstable-spinner";
const spinner = new Spinner({ message: "Loading..." });
spinner.start();
stop
stop(): voidStops 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);