// Vendored from senpi packages/tui/src/terminal-text.ts (not exported by pi 0.83.0). // Strips ANSI escapes and control characters and collapses whitespace so a // terminal label can never inject escape sequences or break layout. const TERMINAL_ESCAPE_PATTERN = /(?:\u001B\][\s\S]*?(?:\u0007|\u001B\\|\u009C))|[\u001B\u009B][[\]()#;?]*(?:\d{1,4}(?:[;:]\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]/g; export function sanitizeTerminalLabel(value: string): string { return value .replace(TERMINAL_ESCAPE_PATTERN, "") .replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ") .replace(/\s+/g, " ") .trim(); }