UNPKG

bananass-utils-console

Version:

Console Utilities for Bananass Framework.🍌

174 lines (173 loc) • 5.03 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 ForegroundColorName = "black" | "red" | "green" | "yellow" | "blue" | "cyan" | "magenta" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "cyanBright" | "magentaBright" | "whiteBright"; export type SpinnerStyle = { frames: string[]; interval?: number; }; /** * Spinner options. */ export type Options = { /** * Text to display next to the spinner. (default: `''`) */ text?: string; /** * The color of the spinner. (default: `'yellow'`) */ color?: ForegroundColorName; /** * The stream to which the spinner is written. (default: `process.stderr`) */ stream?: NodeJS.WriteStream; /** * Whether the spinner should be interactive. (default: Auto-detected) */ isInteractive?: boolean; /** * 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; }; /** * @typedef {'black'|'red'|'green'|'yellow'|'blue'|'cyan'|'magenta'|'white'|'gray'|'grey'|'blackBright'|'redBright'|'greenBright'|'yellowBright'|'blueBright'|'cyanBright'|'magentaBright'|'whiteBright'} ForegroundColorName */ /** * @typedef {object} SpinnerStyle * @property {string[]} frames * @property {number} [interval] */ /** * @typedef {object} Options Spinner options. * @property {string} [text] Text to display next to the spinner. (default: `''`) * @property {ForegroundColorName} [color] The color of the spinner. (default: `'yellow'`) * @property {NodeJS.WriteStream} [stream] The stream to which the spinner is written. (default: `process.stderr`) * @property {boolean} [isInteractive] Whether the spinner should be interactive. (default: Auto-detected) * @property {SpinnerStyle} [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: ForegroundColorName); /** * Change the spinner color. */ get color(): ForegroundColorName; /** * Returns whether the spinner is currently spinning. */ get isSpinning(): boolean; #private; } export {};