* Identify the type of escape sequence from its raw form.
( seq: string, )
| 243 | * Identify the type of escape sequence from its raw form. |
| 244 | */ |
| 245 | function identifySequence( |
| 246 | seq: string, |
| 247 | ): 'csi' | 'osc' | 'esc' | 'ss3' | 'unknown' { |
| 248 | if (seq.length < 2) return 'unknown' |
| 249 | if (seq.charCodeAt(0) !== C0.ESC) return 'unknown' |
| 250 | |
| 251 | const second = seq.charCodeAt(1) |
| 252 | if (second === 0x5b) return 'csi' // [ |
| 253 | if (second === 0x5d) return 'osc' // ] |
| 254 | if (second === 0x4f) return 'ss3' // O |
| 255 | return 'esc' |
| 256 | } |
| 257 | |
| 258 | // ============================================================================= |
| 259 | // Main Parser |