Spinner
Animated loading indicator for async operations.
Preview
Running
spinner
◒ Installing dependencies...
Completed
spinner
◆ Dependencies installed.
Usage
import { spinner } from 'termprompt';
const s = spinner();
s.start('Installing dependencies...');
await install();
s.stop('Dependencies installed.');
API
spinner(config?)
Returns a Spinner object.
| Config | Type | Default | Description |
|---|---|---|---|
output | Writable | process.stdout | Output stream |
Spinner Methods
| Method | Description |
|---|---|
start(message: string) | Show the spinner with a message |
message(text: string) | Update message while spinning |
stop(message?: string, code?) | Stop and show final message |
Stop Codes
| Code | Icon |
|---|---|
0 (default) | Diamond, uses success color |
| Non-zero | Triangle, uses error color |
const s = spinner();
s.start('Deploying...');
try {
await deploy();
s.stop('Deployed successfully.');
} catch (err) {
s.stop('Deploy failed.', 1);
}
error stop code
▲ Deploy failed.
Updating the Message
const s = spinner();
s.start('Downloading...');
s.message('Downloading... 50%');
s.message('Downloading... 100%');
s.stop('Download complete.');
Animation
The spinner cycles through ◒ ◐ ◓ ◑ at 80ms intervals. The animation character uses your accent color.