* Process a chunk of input data
(str: string)
| 70 | * Process a chunk of input data |
| 71 | */ |
| 72 | function processChunk(str: string): void { |
| 73 | let i = 0 |
| 74 | while (i < str.length) { |
| 75 | const char = str[i]! |
| 76 | const code = char.charCodeAt(0) |
| 77 | |
| 78 | // Ctrl+C (code 3) - stop capturing and exit immediately. |
| 79 | // We use process.exit here instead of gracefulShutdown because at this |
| 80 | // early stage of startup, the shutdown machinery isn't initialized yet. |
| 81 | if (code === 3) { |
| 82 | stopCapturingEarlyInput() |
| 83 | // eslint-disable-next-line custom-rules/no-process-exit |
| 84 | process.exit(130) // Standard exit code for Ctrl+C |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | // Ctrl+D (code 4) - EOF, stop capturing |
| 89 | if (code === 4) { |
| 90 | stopCapturingEarlyInput() |
| 91 | return |
| 92 | } |
| 93 | |
| 94 | // Backspace (code 127 or 8) - remove last grapheme cluster |
| 95 | if (code === 127 || code === 8) { |
| 96 | if (earlyInputBuffer.length > 0) { |
| 97 | const last = lastGrapheme(earlyInputBuffer) |
| 98 | earlyInputBuffer = earlyInputBuffer.slice(0, -(last.length || 1)) |
| 99 | } |
| 100 | i++ |
| 101 | continue |
| 102 | } |
| 103 | |
| 104 | // Skip escape sequences (arrow keys, function keys, focus events, etc.) |
| 105 | // All escape sequences start with ESC (0x1B) and end with a byte in 0x40-0x7E |
| 106 | if (code === 27) { |
| 107 | i++ // Skip the ESC character |
| 108 | // Skip until the terminating byte (@ to ~) or end of string |
| 109 | while ( |
| 110 | i < str.length && |
| 111 | !(str.charCodeAt(i) >= 64 && str.charCodeAt(i) <= 126) |
| 112 | ) { |
| 113 | i++ |
| 114 | } |
| 115 | if (i < str.length) i++ // Skip the terminating byte |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | // Skip other control characters (except tab and newline) |
| 120 | if (code < 32 && code !== 9 && code !== 10 && code !== 13) { |
| 121 | i++ |
| 122 | continue |
| 123 | } |
| 124 | |
| 125 | // Convert carriage return to newline |
| 126 | if (code === 13) { |
| 127 | earlyInputBuffer += '\n' |
| 128 | i++ |
| 129 | continue |
no test coverage detected