UNPKG

bananass-utils-console

Version:

Console Utilities for Bananass Framework.🍌

174 lines (173 loc) • 5.13 kB
/** * Create a new spinner instance. * * @param {Options} [options] * @returns {Spinner} A new spinner instance. * * @example * import createSpinner from 'bananass-utils-console/spinner'; * * const spinner = createSpinner({ * text: 'Loading…' * color: 'yellow', * stream: process.stderr, * spinner: { * frames: ['-', '\\', '|', '/'], * interval: 100, * }, * }).start(); * * setTimeout(() => { * spinner.success('Success!'); * }, 2000); */ export default function createSpinner(options?: Options): Spinner; export type ForegroundColors = "black" | "blackBright" | "blue" | "blueBright" | "cyan" | "cyanBright" | "gray" | "green" | "greenBright" | "grey" | "magenta" | "magentaBright" | "red" | "redBright" | "white" | "whiteBright" | "yellow" | "yellowBright"; export type SpinnerStyle = { frames: string[]; interval: number; }; /** * Spinner options. */ export type Options = { /** * Text to display next to the spinner. (default: `''`) */ text?: string | undefined; /** * The color of the spinner. (default: `'yellow'`) */ color?: ForegroundColors | undefined; /** * The stream to which the spinner is written. (default: `process.stderr`) */ stream?: NodeJS.WriteStream | undefined; /** * Whether the spinner should be interactive. (default: Auto-detected) */ isInteractive?: boolean | undefined; /** * Customize the spinner animation with a custom set of frames and interval. * * ``` * { * frames: ['-', '\\', '|', '/'], * interval: 100, * } * ``` * * Pass in any spinner from [`cli-spinners`](https://github.com/sindresorhus/cli-spinners). */ spinner?: SpinnerStyle | undefined; }; /** * @typedef {"black"|"blackBright"|"blue"|"blueBright"|"cyan"|"cyanBright"|"gray"|"green"|"greenBright"|"grey"|"magenta"|"magentaBright"|"red"|"redBright"|"white"|"whiteBright"|"yellow"|"yellowBright"} ForegroundColors */ /** * @typedef {object} SpinnerStyle * @property {string[]} frames * @property {number} interval */ /** * @typedef {object} Options Spinner options. * @property {string | undefined} [text] Text to display next to the spinner. (default: `''`) * @property {ForegroundColors | undefined} [color] The color of the spinner. (default: `'yellow'`) * @property {NodeJS.WriteStream | undefined} [stream] The stream to which the spinner is written. (default: `process.stderr`) * @property {boolean | undefined} [isInteractive] Whether the spinner should be interactive. (default: Auto-detected) * @property {SpinnerStyle | undefined} [spinner] * Customize the spinner animation with a custom set of frames and interval. * * ``` * { * frames: ['-', '\\', '|', '/'], * interval: 100, * } * ``` * * Pass in any spinner from [`cli-spinners`](https://github.com/sindresorhus/cli-spinners). */ declare class Spinner { /** @param {Options} options */ constructor(options?: Options); /** * Starts the spinner. * * Optionally, updates the text. * * @param {string} [text] The text to display next to the spinner. * @returns The spinner instance. */ start(text?: string): this; /** * Stops the spinner. * * Optionally displays a final message. * * @param {string} [finalText] The final text to display after stopping the spinner. * @returns The spinner instance. */ stop(finalText?: string): this; /** * Stops the spinner and displays a success symbol with the message. * * @param {string} [text] The success message to display. * @returns The spinner instance. */ success(text?: string): this; /** * Stops the spinner and displays an error symbol with the message. * * @param {string} [text] The error message to display. * @returns The spinner instance. */ error(text?: string): this; /** * Stops the spinner and displays a warning symbol with the message. * * @param {string} [text] The warning message to display. * @returns The spinner instance. */ warning(text?: string): this; /** * Stops the spinner and displays an info symbol with the message. * * @param {string} [text] The info message to display. * @returns The spinner instance. */ info(text?: string): this; /** * Clears the spinner. * * @returns The spinner instance. */ clear(): this; /** * Change the text displayed next to the spinner. * * @example * spinner.text = 'New text'; */ set text(value: string); /** * Change the text displayed next to the spinner. * * @example * spinner.text = 'New text'; */ get text(): string; /** * Change the spinner color. */ set color(value: ForegroundColors); /** * Change the spinner color. */ get color(): ForegroundColors; /** * Returns whether the spinner is currently spinning. */ get isSpinning(): boolean; #private; } export {};