tora-spinner
v1.0.5
Published
A thread/worker spinner based on ora/yocto-spinner ✨
Downloads
30
Maintainers
Readme
Install
With npm
npm i tora-spinner
With yarn
yarn add tora-spinner
Usage
import tora from "tora-spinner";
const spinner = tora({ text: "Loading…" });
async function main() {
await spinner.start();
// Do some work
await new Promise((resolve) => setTimeout(resolve, 1000));
await spinner.stop("Stopped.");
// Kill spinner worker thread
spinner.terminate();
}
main();
API
tora(options?)
Creates a new spinner instance.
options
Type: object
text
Type: string
Default: ''
The text to display next to the spinner.
spinner
Type: object
Default:
Customize the spinner animation with a custom set of frames and interval.
{
frames: ['-', '\\', '|', '/'],
interval: 100,
}
Pass in any spinner from cli-spinners
.
color
Type: string
Default: 'cyan'
Values: 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray'
The color of the spinner.
stream
Type: stream.Writable
Default: process.stderr
The stream to which the spinner is written.
Instance methods
.start(text?)
Starts the spinner.
Returns the instance.
Optionally, updates the text:
spinner.start("Loading…");
.stop(finalText?)
Stops the spinner.
Returns the instance.
Optionally displays a final message.
spinner.stop("Stopped.");
.success(text?)
Stops the spinner and displays a success symbol with the message.
Returns the instance.
spinner.success("Success!");
.error(text?)
Stops the spinner and displays an error symbol with the message.
Returns the instance.
spinner.error("Error!");
.warning(text?)
Stops the spinner and displays a warning symbol with the message.
Returns the instance.
spinner.warning("Warning!");
.clear()
Clears the spinner.
Returns the instance.
.info(text?)
Stops the spinner and displays an info symbol with the message.
Returns the instance.
.terminate()
Kills the spinner worker thread.
Returns void.
spinner.info("Info.");
.text get/set
Change the text displayed next to the spinner.
spinner.text = "New text";
.color get/set
Change the spinner color.
.isSpinning get
Returns whether the spinner is currently spinning.
Credits
- ora - terminal spinner
- yocto-spinner - terminal spinner