//#region src/core/help/ansi.d.ts /** * ANSI/OSC-aware text helpers for help formatting. * * Terminal escape sequences (SGR colors, OSC 8 hyperlinks) occupy zero * columns when rendered, so width math must measure the *visible* text. * {@linkcode visibleWidth} strips escapes before counting, and the shared * {@linkcode padEnd}/{@linkcode wrapText} helpers build on it so aligned * tables and wrapped lines stay intact when escapes are present. * * @module dreamcli/core/help/ansi */ /** * Remove ANSI CSI and OSC escape sequences from `text`. * * Delegates to `ansispeck`'s stripper, which handles SGR sequences and OSC * hyperlinks under both terminators. Kept as a named export so help * formatting and custom help renderers reach the width-aware helpers and * their stripper through one module. * * @param text - Text possibly containing terminal escapes. * @returns The text with all escape sequences removed. */ declare function stripAnsi(text: string): string; /** * Measure the visible column width of `text`, ignoring ANSI/OSC escapes. * * Escape sequences (SGR colors, OSC 8 hyperlinks) occupy zero columns when * rendered, so `.length` overcounts whenever they are present. Help * formatting uses this for padding and wrapping; exported for custom help * renderers that mix colors or links into aligned output. * * @param text - Text possibly containing terminal escapes. * @returns Number of visible characters. * * @example * ```ts * visibleWidth('plain'); // 5 * visibleWidth(osc8('https://x.dev', 'x')); // 1 * ``` */ declare function visibleWidth(text: string): number; /** * Wrap `text` in an [OSC 8 hyperlink](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) * pointing at `url`. * * Supporting terminals render `text` as a clickable link; others show it * plain. `text` defaults to the URL, so an omitted label degrades to a * usable address. The framework's help layer decides *whether* to link * (`help.hyperlinks`); this always emits when called. * * @param url - Link target (string or `URL` instance). * @param text - Visible link text. * @returns The OSC 8 escape sequence wrapping `text`. * * @example * ```ts * cli('mycli').version(osc8('https://github.com/me/mycli/releases/tag/v1.0.0', '1.0.0')); * osc8('https://dreamcli.kjanat.dev'); // linked, displayed as the URL * ``` */ declare function osc8(url: string | URL, text?: string): string; /** * Pad `text` to `length` visible columns with trailing spaces. * * @param text - The string to pad (may contain ANSI/OSC escapes). * @param length - Target visible width in columns. * @returns The padded string, unchanged if already at or beyond `length`. */ declare function padEnd(text: string, length: number): string; /** * Wrap text to `width`, preserving leading indent on continuation lines. * * Line lengths are measured with {@linkcode visibleWidth}, so embedded * ANSI/OSC escapes do not trigger premature wrapping. * * @param text - The text to wrap. * @param width - Maximum line width in columns. * @param indent - Number of leading spaces for continuation lines. * @returns The wrapped string with newlines inserted as needed. */ declare function wrapText(text: string, width: number, indent: number): string; //#endregion export { osc8, padEnd, stripAnsi, visibleWidth, wrapText };