/** * ANSI escape code parser for terminal colorization. * * Handles standard ANSI/VT100 escape sequences including: * - CSI (Control Sequence Introducer): \x1b[... * - SGR (Select Graphic Rendition): colors, styles * - OSC (Operating System Command): window title, etc. * * Converts ANSI codes to xterm.js compatible format with proper * Synthwave theme color mapping. * * @module components/devenv/terminal/parsing/ansi/parser */ import type { IAnsiParseResult } from '../LogParser.types'; /** * ANSI escape code parser class. * * Parses ANSI escape sequences from text and converts them to * xterm.js compatible format with proper Synthwave theme colors. * * @example * ```ts * const parser = new AnsiParser(); * const result = parser.parse('\x1b[31mError\x1b[0m message'); * // result.text: '\\x1b]4;197;#ff4466\\x07Error\\x1b[0m message' * // result.styles: [{ fg_color: 31, modifiers: [] }] * ``` */ export declare class AnsiParser { /** Current parser state */ private state; /** * Create a new ANSI parser. * * Initializes with default state (no colors, no modifiers). */ constructor(); /** * Check if a string contains ANSI escape codes. * * @param text - Text to check * @returns true if text contains ANSI escape sequences * * @example * ```ts * AnsiParser.hasAnsi('\x1b[31mError'); // true * AnsiParser.hasAnsi('Plain text'); // false * ``` */ static hasAnsi(text: string): boolean; /** * Strip all ANSI escape codes from text. * * Removes ANSI sequences while preserving the actual text content. * Useful for plain text display or searching. * * @param text - Text with ANSI codes * @returns Plain text without ANSI codes * * @example * ```ts * const plain = AnsiParser.stripAnsi('\x1b[31mError\x1b[0m'); * // 'Error' * ``` */ static stripAnsi(text: string): string; /** * Parse ANSI codes and convert to xterm.js format. * * Converts ANSI CSI sequences to xterm.js OSC sequences for * true-color support and applies Synthwave theme colors. * * @param text - Text with ANSI escape codes * @returns Parse result with converted text and extracted styles * * @example * ```ts * const result = parser.parse('\x1b[31;1mError\x1b[0m'); * // result.text: xterm.js formatted string * // result.styles: [{ fg_color: 31, modifiers: ['bold'] }] * ``` */ parse(text: string): IAnsiParseResult; /** * Get ANSI color code as hex from theme. * * Converts an ANSI color code to its hex color value in the * Synthwave theme. * * @param code - ANSI color code (e.g., 31 for red) * @returns Hex color string (e.g., '#ff4466') or undefined */ colorFromAnsi(code: number): string | undefined; /** * Reset parser state to defaults. */ reset(): void; /** * Parse SGR (Select Graphic Rendition) parameters from CSI sequence. * * @param sequence - CSI sequence (e.g., '\x1b[31;1m') * @returns Array of parameter numbers * @private */ private parseSgrParams; /** * Apply SGR parameters to parser state. * * Updates internal state based on SGR parameters and returns * the current style after applying changes. * * @param params - Array of SGR parameter numbers * @returns Current style after applying parameters * @private */ private applySgrParams; /** * Convert ANSI CSI sequence to xterm.js OSC format. * * xterm.js supports OSC sequences for true-color (24-bit) colors. * This converts ANSI 4-bit/8-bit colors to OSC 4/10/11 sequences. * * @param sequence - Original ANSI CSI sequence * @param params - Parsed SGR parameters * @returns xterm.js compatible escape sequence * @private */ private convertToXterm; /** * Extract all ANSI escape codes from text. * * Returns an array of all ANSI sequences found in the text. * * @param text - Text to extract from * @returns Array of ANSI escape sequences * * @example * ```ts * const codes = AnsiParser.extractCodes('\x1b[31mError\x1b[0m'); * // ['\x1b[31m', '\x1b[0m'] * ``` */ static extractCodes(text: string): string[]; /** * Count ANSI escape codes in text. * * @param text - Text to count codes in * @returns Number of ANSI escape sequences */ static countCodes(text: string): number; /** * Get visible text length (excluding ANSI codes). * * @param text - Text with potential ANSI codes * @returns Length of visible text only * * @example * ```ts * AnsiParser.visibleLength('\x1b[31mError\x1b[0m'); // 5 * ``` */ static visibleLength(text: string): number; } //# sourceMappingURL=AnsiParser.d.ts.map