import { InspectOptions } from 'node:util'; import { OutputTextMacros, OutputUiMacros } from './types/output.js'; import { ColorInstance, t, template } from './utils/color.js'; import { Macroable } from './utils/macroable.js'; import * as term_size from 'term-size'; import ora from 'ora'; import CliTable3 from 'cli-table3'; import figlet from 'figlet'; import { Animation, AnimationFn } from 'chalk-animation'; interface AliasGradientFunction { (str: string): string; multiline: (str: string) => string; } type GradientTypes = 'atlas' | 'cristal' | 'teen' | 'mind' | 'morning' | 'vice' | 'passion' | 'fruit' | 'instagram' | 'retro' | 'summer' | 'rainbow' | 'pastel'; interface Gradients extends Record { } type AnimationType = 'rainbow' | 'pulse' | 'glitch' | 'radar' | 'neon' | 'karaoke'; interface Animations extends Record { } declare class OutputText { protected output: Output; constructor(output: Output); figlet(txt: string, font: figlet.Fonts, cb?: (error: Error | null, result?: string) => void): Promise; figlet(txt: string, options: figlet.Options | undefined, cb?: (error: Error | null, result?: string) => void): Promise; figlet(txt: string, cb?: (error: Error | null, result?: string) => void): Promise; gradient(gradient: GradientTypes, str: string): string; multilineGradient(gradient: GradientTypes, str: string): string; animation(animation: AnimationType, text: string, speed?: number): Animation; widest(input: string[]): number; /** Truncate a string to a specific width in the terminal. @param text - The text to truncate. @param columns - The number of columns to occupy in the terminal. @example import cliTruncate from 'cli-truncate'; cliTruncate('unicorn', 4); //=> 'uni…' // Truncate at different positions cliTruncate('unicorn', 4, {position='start'}); //=> '…orn' cliTruncate('unicorn', 4, {position='middle'}); //=> 'un…n' cliTruncate('\u001B[31municorn\u001B[39m', 4); //=> '\u001B[31muni\u001B[39m…' // Truncate Unicode surrogate pairs cliTruncate('uni\uD83C\uDE00corn', 5); //=> 'uni\uD83C\uDE00…' // Truncate fullwidth characters cliTruncate('안녕하세요', 3); //=> '안…' // Truncate the paragraph to the terminal width const paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.'; cliTruncate(paragraph, process.stdout.columns); //=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…' */ truncate(...args: any[]): any; /** Wrap words to the specified column width. @param string - A string with ANSI escape codes, like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`. @param columns - The number of columns to wrap the text to. @method @example import chalk from 'chalk'; import wrapAnsi from 'wrap-ansi'; const input = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.'); console.log(wrapAnsi(input, 20)); */ wrap(...args: any[]): any; /** Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) @param string - A string with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). @param startSlice - Zero-based index at which to start the slice. @param endSlice - Zero-based index at which to end the slice. @method @example import chalk from 'chalk'; import sliceAnsi from 'slice-ansi'; const string = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.'); console.log(sliceAnsi(string, 20, 30)); */ slice(...args: any[]): any; /** Get the visual width of the widest line in a string - the number of columns required to display it. @method @example import widestLine from 'widest-line'; widestLine('古\n\u001B[1m@\u001B[22m'); //=> 2 */ widestLine(...args: any[]): any; /** Get the visual width of a string - the number of columns required to display it. Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width. @method @example import stringWidth from 'string-width'; stringWidth('a'); //=> 1 stringWidth('古'); //=> 2 stringWidth('\u001B[1m古\u001B[22m'); //=> 2 */ width(...args: any[]): any; /** * Strips ANSI escape codes from a string. * @param {string} text - The text to strip * @returns {string} The stripped text * @example * stripAnsi('\u001B[4mUnicorn\u001B[0m'); * //=> 'Unicorn' * * stripAnsi('\u001B] 8;;https:// github. com\u0007Click\u001B] 8;;\u0007'); * //=> 'Click' */ strip(...args: any[]): any; } /** * Represents the border characters used in table rendering. * * @property {string} top - The character for the top border. * @property {string} topMid - The character for the top middle border. * @property {string} topLeft - The character for the top left corner. * @property {string} topRight - The character for the top right corner. * @property {string} bottom - The character for the bottom border. * @property {string} bottomMid - The character for the bottom middle border. * @property {string} bottomLeft - The character for the bottom left corner. * @property {string} bottomRight - The character for the bottom right corner. * @property {string} left - The character for the left border. * @property {string} leftMid - The character for the left middle border. * @property {string} mid - The character for the middle border. * @property {string} midMid - The character for the middle middle border. * @property {string} right - The character for the right border. * @property {string} rightMid - The character for the right middle border. * @property {string} middle - The character for the middle of the table. * * @example * const border: Border = { * top: '─', * topMid: '┬', * topLeft: '┌', * topRight: '┐', * bottom: '─', * bottomMid: '┴', * bottomLeft: '└', * bottomRight: '┘', * left: '│', * leftMid: '├', * mid: '─', * midMid: '┼', * right: '│', * rightMid: '┤', * middle: '│', * }; */ interface Border { top: string; topMid: string; topLeft: string; topRight: string; bottom: string; bottomMid: string; bottomLeft: string; bottomRight: string; left: string; leftMid: string; mid: string; midMid: string; right: string; rightMid: string; middle: string; } /** * Represents a collection of different border styles. * * @property {Border} single - Single line border style. * @property {Border} double - Double line border style. * @property {Border} borderless - Borderless style. * @property {Record} [key: string] - Additional custom border styles. * * @example * const borders: Borders = { * single: { ... }, * double: { ... }, * borderless: { ... }, * custom: { ... }, * }; */ interface Borders { single: Border; double: Border; borderless: Border; [key: string]: Border; } /** * Represents the type of border used in table rendering. * * @example * const borderType: BorderType = 'single'; */ type BorderType = keyof Borders; /** * Options for configuring the title display in the `OutputUI` class. * * @property {BorderType} [border='single'] - The type of border to use. * @property {number} [padding=6] - The padding around the title text. * @property {(str: string) => string} [colorizeBorder] - Function to colorize the border. * @property {(str: string) => string} [colorizeTitle] - Function to colorize the title text. * * @example * const titleOptions: TitleOptions = { * border: 'double', * padding: 4, * colorizeBorder: str => `\x1b[34m${str}\x1b[0m`, * colorizeTitle: str => `\x1b[32m${str}\x1b[0m`, * }; */ interface TitleOptions { border?: BorderType; padding?: number; colorizeBorder?: (str: string) => string; colorizeTitle?: (str: string) => string; } /** * Options for configuring the list display in the `OutputUI` class. * * @property {string} [title] - The title of the list. * @property {BorderType} [border='single'] - The type of border to use. * @property {number} [padding=2] - The padding around the list items. * @property {(str: string) => string} [colorizeTitle] - Function to colorize the title text. * @property {(str: string) => string} [colorizeBorder] - Function to colorize the border. * @property {(str: string) => string} [colorizeItem] - Function to colorize the list items. * * @example * const listOptions: ListOptions = { * title: 'My List', * border: 'single', * padding: 2, * colorizeTitle: str => `\x1b[32m${str}\x1b[0m`, * colorizeBorder: str => `\x1b[34m${str}\x1b[0m`, * colorizeItem: str => `\x1b[36m${str}\x1b[0m`, * }; */ interface ListOptions { title?: string; border?: BorderType; padding?: number; colorizeTitle?: (str: string) => string; colorizeBorder?: (str: string) => string; colorizeItem?: (str: string) => string; } /** * Options for configuring the table constructor in the `OutputUI` class. * * @property {BorderType} [border='borderless'] - The type of border to use. * @property {CliTable3.TableConstructorOptions} [chars] - Custom characters for the table. * @property {CliTable3.TableConstructorOptions} [style] - Style options for the table. * @property {boolean} [wordWrap=true] - Whether to enable word wrapping. * * @example * const tableOptions: TableConstructorOptions = { * border: 'double', * chars: { ... }, * style: { 'padding-left': 1, 'padding-right': 1 }, * wordWrap: true, * }; */ interface TableConstructorOptions extends CliTable3.TableConstructorOptions { border?: BorderType; } /** * The `OutputUI` class provides methods for rendering formatted and styled console output, including titles, lists, and tables. * * @property {typeof ora} ora - The ora spinner instance. * @property {Borders} borders - The available border styles. * @property {typeof CliTable3} Table - The table constructor. * * @example * const outputUI = new OutputUI(output); * outputUI.title('My Title'); * outputUI.list(['Item 1', 'Item 2']); * const table = outputUI.createTable({ border: 'single' }); * table.push(['Row 1', 'Row 2']); * console.log(table.toString()); */ declare class OutputUI { protected output: Output; ora: typeof ora; borders: Borders; Table: typeof CliTable3; /** * Creates an instance of `OutputUI`. * * @param {Output} output - The `Output` instance to use for rendering. * * @example * const outputUI = new OutputUI(output); */ constructor(output: Output); /** * Renders a title with the specified options. * * @param {string} text - The title text to render. * @param {TitleOptions} [_options={}] - The options for rendering the title. * * @example * outputUI.title('My Title', { border: 'double', padding: 4 }); */ title(text: string, _options?: TitleOptions): void; /** * Renders a list with the specified items and options. * * @param {string[]} items - The list items to render. * @param {ListOptions} [_options={}] - The options for rendering the list. * * @example * outputUI.list(['Item 1', 'Item 2'], { title: 'My List', border: 'single' }); */ list(items: string[], _options?: ListOptions): void; /** * Renders a table with the specified rows and options. * * @param {any[]} rows - The rows to render in the table. * @param {TableConstructorOptions} [options={}] - The options for rendering the table. * @returns {string} The rendered table as a string. * * @example * const table = outputUI.table([['Row 1', 'Row 2']], { border: 'single' }); * console.log(table); */ table(rows: any[], options?: TableConstructorOptions): string; /** * Creates a table with the specified options. * * @param {TableConstructorOptions} [options={}] - The options for creating the table. * @returns {CliTable3} The created table instance. * * @example * const table = outputUI.createTable({ border: 'single' }); * table.push(['Row 1', 'Row 2']); * console.log(table.toString()); */ createTable(options?: TableConstructorOptions): CliTable3.Table; /** * Gets the current terminal size. * * @returns {terminalSize.Size} The current terminal size. * * @example * const size = outputUI.size(); * console.log(`Width: ${size.columns}, Height: ${size.rows}`); */ size(): term_size.TerminalSize; } type CallbackOrValue = T | (() => T); /** * Options for configuring the `Output` class. * * @property {boolean} [silent=false] - If true, suppresses all output. * @property {boolean} [colors=true] - If true, enables colored output. * @property {NodeJS.WriteStream} [out=process.stdout] - The output stream for standard messages. * @property {NodeJS.WriteStream} [err=process.stderr] - The output stream for error messages. * @property {boolean} [resetOnNewLine=true] - If true, resets styles on new lines. * @property {Record} [styles] - Custom styles for different message types. * @property {InspectOptions} [inspectOptions] - Options for the `util.inspect` method. * * @example typescript * const options: OutputOptions = { * silent: true, * colors: false, * out: process.stdout, * err: process.stderr, * resetOnNewLine: false, * styles: { * title: ['blue', 'bold'], * error: ['red', 'underline'] * }, * inspectOptions: { depth: 2, colors: true } * }; */ interface OutputOptions { silent?: CallbackOrValue; colors?: CallbackOrValue; out?: typeof process.stdout; err?: typeof process.stderr; resetOnNewLine?: boolean; styles?: Record; inspectOptions?: InspectOptions; } /** * The `Output` class provides methods for formatted and styled console output. * - If we put `options.silent` to `true`, nothing will be printed * - If we put `options.colors` to `false`, no colors will be printed * * @example * const out = new Output({ silent: false }); * out.write('Hello, World!'); * out.success('Operation completed successfully.'); * out.error('An error occurred.'); * out.line(out.t`Hello {green.bold.dim World, this is colored!} and this aint` * out.line(`Hello {green.bold.dim World, this is colored!} and this aint`) * out.line(out.color.red('This is red text')); * */ declare class Output { static defaultOptions: OutputOptions; /** * The output stream for standard messages. * @type {typeof process.stdout} @returns {typeof process.stdout} * @readonly * @example * output.out.write('Hello, World!'); * output.out.write('Hello, World!').write('Hello, World!'); * output.out.write('Hello, World!').writeln('Hello, World!'); */ get out(): typeof process.stdout; /** * The output stream for standard messages. * @type {typeof NodeJS.Process.stdout} @returns {typeof NodeJS.Process.stdout} * @readonly * @example * output.out.write('Hello, World!'); * output.out.write('Hello, World!').write('Hello, World!'); * output.out.write('Hello, World!').writeln('Hello, World!'); */ get err(): typeof process.stderr; color: ColorInstance; /** * * Blocks are delimited by an opening curly brace ({), a style, some content, and a closing curly brace (}). * Template styles are chained exactly like normal Chalk styles. * * @see https://github.com/chalk/chalk-template * @example * console.log(t` * There are also {#FF0000 shorthand hex styles} for * both the {#ABCDEF foreground}, {#:123456 background}, * or {#ABCDEF:123456 both}. * * There are {bold 5280 feet} in a mile. * In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}. * `) * * // Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent * console.log(chalk.bold.rgb(10, 100, 200)('Hello!')); * console.log(chalkTemplate`{bold.rgb(10,100,200) Hello!}`); */ t: typeof t; template: typeof template; readonly text: Macroable; readonly ui: Macroable; options: OutputOptions; protected silent(): boolean; protected colors(): boolean; /** * Creates an instance of `Output`. * * @param {Partial} options - Partial options to override the default settings. * * @example * const output = new Output({ silent: true }); */ constructor(options: Partial); /** * Configures the `Output` instance with new options. * * @param {Partial} options - Partial options to merge with the current settings. * @returns {this} The current `Output` instance. * * @example * output.configure({ colors: false }); */ configure(options: Partial): this; get nl(): this; /** * Writes text to the output stream. * * @param {string} text - The text to write. * @param useTemplateColoring * @returns {this} The current `Output` instance. * * @example * output.write('Hello, World!'); */ write(text: string, useTemplateColoring?: boolean): this; /** * Writes text followed by a newline to the output stream. * * @param {string} [text=''] - The text to write. * @param useTemplateColoring * @returns {this} The current `Output` instance. * * @example * output.writeln('Hello, World!'); */ writeln(text?: string, useTemplateColoring?: boolean): this; /** * Writes text followed by a newline to the output stream. * * @param {string} [text=''] - The text to write. * @param useTemplateColoring * @returns {this} The current `Output` instance. * * @example * output.line('Hello, World!'); */ line(text?: string, useTemplateColoring?: boolean): this; /** * Dumps the provided arguments to the output stream using `util.inspect`. * * @param {...any[]} args - The arguments to dump. * @returns {this} The current `Output` instance. * * @example * output.dump({ key: 'value' }, [1, 2, 3]); */ dump(...args: any[]): this; /** * Writes a success message to the output stream. * * @param {string} text - The success message. * @returns {this} The current `Output` instance. * * @example * output.success('Operation completed successfully.'); */ success(text: string): this; /** * Writes a warning message to the output stream. * * @param {string} text - The warning message. * @returns {this} The current `Output` instance. * * @example * output.warn('This is a warning message.'); */ warn(text: string): this; /** * Writes an error message to the output stream. * * @param {string} text - The error message. * @returns {this} The current `Output` instance. * * @example * output.error('An error occurred.'); */ error(text: string): this; } export { type AliasGradientFunction as A, type Border as B, type CallbackOrValue as C, type GradientTypes as G, type ListOptions as L, type OutputOptions as O, type TitleOptions as T, Output as a, type Gradients as b, type AnimationType as c, type Animations as d, OutputText as e, type Borders as f, type BorderType as g, type TableConstructorOptions as h, OutputUI as i };