* Identify the type of escape sequence from its raw form.
( seq: string, )
| 289 | * Identify the type of escape sequence from its raw form. |
| 290 | */ |
| 291 | function identifySequence( |
| 292 | seq: string, |
| 293 | ): 'csi' | 'osc' | 'esc' | 'ss3' | 'unknown' { |
| 294 | if (seq.length < 2) return 'unknown' |
| 295 | if (seq.charCodeAt(0) !== C0.ESC) return 'unknown' |
| 296 | |
| 297 | const second = seq.charCodeAt(1) |
| 298 | if (second === 0x5b) return 'csi' // [ |
| 299 | if (second === 0x5d) return 'osc' // ] |
| 300 | if (second === 0x4f) return 'ss3' // O |
| 301 | return 'esc' |
| 302 | } |
| 303 | |
| 304 | // ============================================================================= |
| 305 | // Main Parser |