* Strip characters that can break terminal rendering. * * Uses Node.js built-in stripVTControlCharacters to handle VT sequences, * then filters remaining control characters that can disrupt display. * * Characters stripped: * - ANSI escape sequences (via strip-ansi) * - VT control sequences (
(str: string)
| 513 | * - CR/LF (0x0D/0x0A) - needed for line breaks |
| 514 | */ |
| 515 | function stripUnsafeCharacters(str: string): string { |
| 516 | const strippedAnsi = stripAnsi(str); |
| 517 | const strippedVT = stripVTControlCharacters(strippedAnsi); |
| 518 | |
| 519 | return toCodePoints(strippedVT) |
| 520 | .filter((char) => { |
| 521 | const code = char.codePointAt(0); |
| 522 | if (code === undefined) return false; |
| 523 | |
| 524 | // Preserve CR/LF for line handling |
| 525 | if (code === 0x0a || code === 0x0d) return true; |
| 526 | |
| 527 | // Remove C0 control chars (except CR/LF) that can break display |
| 528 | // Examples: BELL(0x07) makes noise, BS(0x08) moves cursor, VT(0x0B), FF(0x0C) |
| 529 | if (code >= 0x00 && code <= 0x1f) return false; |
| 530 | |
| 531 | // Remove C1 control chars (0x80-0x9F) - legacy 8-bit control codes |
| 532 | if (code >= 0x80 && code <= 0x9f) return false; |
| 533 | |
| 534 | // Preserve DEL (0x7F) - it's handled functionally by applyOperations as backspace |
| 535 | // and doesn't cause rendering issues when displayed |
| 536 | |
| 537 | // Preserve all other characters including Unicode/emojis |
| 538 | return true; |
| 539 | }) |
| 540 | .join(''); |
| 541 | } |
| 542 | |
| 543 | export interface Viewport { |
| 544 | height: number; |
no test coverage detected