ora
- Version 9.3.0
- Published
- 38.1 kB
- 8 dependencies
- MIT license
Install
npm i orayarn add orapnpm add oraOverview
Elegant terminal spinner
Index
Functions
function ora
ora: (options?: string | Options) => Ora;Elegant terminal spinner.
Parameter options
If a string is provided, it is treated as a shortcut for
options.text.Example 1
import ora from 'ora';const spinner = ora('Loading unicorns').start();setTimeout(() => {spinner.color = 'yellow';spinner.text = 'Loading rainbows';}, 1000);
function oraPromise
oraPromise: <T>( action: PromiseLike<T> | ((spinner: Ora) => PromiseLike<T>), options?: string | PromiseOptions<T>) => Promise<T>;Starts a spinner for a promise or promise-returning function. The spinner is stopped with
.succeed()if the promise fulfills or with.fail()if it rejects.Parameter action
The promise to start the spinner for or a promise-returning function.
Parameter options
If a string is provided, it is treated as a shortcut for
options.text.Returns
The given promise.
Example 1
import {oraPromise} from 'ora';await oraPromise(somePromise);
Interfaces
interface Ora
interface Ora {}property color
color: Color | boolean;Change the spinner color.
property indent
indent: number;Change the spinner indent.
property prefixText
prefixText: string;Change the text or function that returns text before the spinner.
No prefix text will be displayed if set to an empty string.
property suffixText
suffixText: string;Change the text or function that returns text after the spinner text.
No suffix text will be displayed if set to an empty string.
property text
text: string;Change the text after the spinner.
method clear
clear: () => this;Clear the spinner.
Returns
The spinner instance.
method fail
fail: (text?: string) => this;Stop the spinner, change it to a red
✖and persist the current text, ortextif provided.Parameter text
Will persist text if provided.
Returns
The spinner instance.
method frame
frame: () => string;Get a new frame.
Returns
The spinner instance text.
method info
info: (text?: string) => this;Stop the spinner, change it to a blue
ℹand persist the current text, ortextif provided.Parameter text
Will persist text if provided.
Returns
The spinner instance.
method render
render: () => this;Manually render a new frame.
Returns
The spinner instance.
method start
start: (text?: string) => this;Start the spinner.
Parameter text
Set the current text.
Returns
The spinner instance.
method stop
stop: () => this;Stop and clear the spinner.
Returns
The spinner instance.
method stopAndPersist
stopAndPersist: (options?: PersistOptions) => this;Stop the spinner and change the symbol or text.
Returns
The spinner instance.
method succeed
succeed: (text?: string) => this;Stop the spinner, change it to a green
✔and persist the current text, ortextif provided.Parameter text
Will persist text if provided.
Returns
The spinner instance.
method warn
warn: (text?: string) => this;Stop the spinner, change it to a yellow
⚠and persist the current text, ortextif provided.Parameter text
Will persist text if provided.
Returns
The spinner instance.
index signature
get spinner(): Spinner;Get the spinner.
index signature
set spinner(spinner: SpinnerName | Spinner);Set the spinner.
index signature
get isSpinning(): boolean;A boolean indicating whether the instance is currently spinning.
index signature
get interval(): number;The interval between each frame.
The interval is decided by the chosen spinner.
Type Aliases
type Color
type Color = | 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray';type Options
type Options = { /** The text to display next to the spinner. */ readonly text?: string;
/** Text or a function that returns text to display before the spinner. No prefix text will be displayed if set to an empty string. */ readonly prefixText?: string | PrefixTextGenerator;
/** Text or a function that returns text to display after the spinner text. No suffix text will be displayed if set to an empty string. */ readonly suffixText?: string | SuffixTextGenerator;
/** The name of one of the provided spinners. See `example.js` in this repo if you want to test out different spinners. On Windows (except for Windows Terminal), it will always use the line spinner as the Windows command-line doesn't have proper Unicode support.
@default 'dots'
Or an object like:
@example ``` { frames: ['-', '+', '-'], interval: 80 // Optional } ``` */ readonly spinner?: SpinnerName | Spinner;
/** The color of the spinner.
@default 'cyan' */ readonly color?: Color | boolean;
/** Set to `false` to stop Ora from hiding the cursor.
@default true */ readonly hideCursor?: boolean;
/** Indent the spinner with the given number of spaces.
@default 0 */ readonly indent?: number;
/** Interval between each frame.
Spinners provide their own recommended interval, so you don't really need to specify this.
Default: Provided by the spinner or `100`. */ readonly interval?: number;
/** Stream to write the output.
You could for example set this to `process.stdout` instead.
@default process.stderr */ readonly stream?: NodeJS.WritableStream;
/** Force enable/disable the spinner. If not specified, the spinner will be enabled if the `stream` is being run inside a TTY context (not spawned or piped) and/or not in a CI environment.
Note that `{isEnabled: false}` doesn't mean it won't output anything. It just means it won't output the spinner, colors, and other ansi escape codes. It will still log text. */ readonly isEnabled?: boolean;
/** Disable the spinner and all log text. All output is suppressed and `isEnabled` will be considered `false`.
@default false */ readonly isSilent?: boolean;
/** Discard stdin input (except Ctrl+C) while running if it's TTY. This prevents the spinner from twitching on input, outputting broken lines on `Enter` key presses, and prevents buffering of input while the spinner is running.
This has no effect on Windows as there is no good way to implement discarding stdin properly there.
Note: `discardStdin` puts stdin into raw mode. In raw mode, `Ctrl+C` no longer generates `SIGINT` from the terminal. Ora re-emits `Ctrl+C` from stdin input, but if your code blocks the event loop with synchronous work, `Ctrl+C` handling is delayed until the blocking work ends. Use async APIs, a worker thread, or a child process to keep `Ctrl+C` responsive, or set `discardStdin` to `false`.
@default true */ readonly discardStdin?: boolean;};type PersistOptions
type PersistOptions = { /** Symbol to replace the spinner with.
@default ' ' */ readonly symbol?: string;
/** Text to be persisted after the symbol.
Default: Current `text`. */ readonly text?: string;
/** Text or a function that returns text to be persisted before the symbol. No prefix text will be displayed if set to an empty string.
Default: Current `prefixText`. */ readonly prefixText?: string | PrefixTextGenerator;
/** Text or a function that returns text to be persisted after the text after the symbol. No suffix text will be displayed if set to an empty string.
Default: Current `suffixText`. */ readonly suffixText?: string | SuffixTextGenerator;};type PrefixTextGenerator
type PrefixTextGenerator = () => string;type PromiseOptions
type PromiseOptions<T> = { /** The new text of the spinner when the promise is resolved.
Keeps the existing text if `undefined`. */ successText?: string | ((result: T) => string) | undefined;
/** The new text of the spinner when the promise is rejected.
Keeps the existing text if `undefined`. */ failText?: string | ((error: Error) => string) | undefined;} & Options;type Spinner
type Spinner = { readonly interval?: number; readonly frames: string[];};type SuffixTextGenerator
type SuffixTextGenerator = () => string;Package Files (1)
Dependencies (8)
Dev Dependencies (6)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ora.
- Markdown[](https://www.jsdocs.io/package/ora)
- HTML<a href="https://www.jsdocs.io/package/ora"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3441 ms. - Missing or incorrect documentation? Open an issue for this package.
