MCPcopy Create free account
hub / github.com/anus-dev/ANUS / stripUnsafeCharacters

Function stripUnsafeCharacters

packages/cli/src/ui/components/shared/text-buffer.ts:515–541  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

513 * - CR/LF (0x0D/0x0A) - needed for line breaks
514 */
515function 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
543export interface Viewport {
544 height: number;

Callers 1

textBufferReducerFunction · 0.85

Calls 1

toCodePointsFunction · 0.85

Tested by

no test coverage detected