skipEscapeSequence advances past a complete ANSI escape sequence starting at i. i must point at '\x1b' and i+1 must be within the string.
(s string, i int)
| 46 | // skipEscapeSequence advances past a complete ANSI escape sequence starting at i. |
| 47 | // i must point at '\x1b' and i+1 must be within the string. |
| 48 | func skipEscapeSequence(s string, i int) int { |
| 49 | switch s[i+1] { |
| 50 | case '[': |
| 51 | return skipCSISequence(s, i) |
| 52 | case ']': |
| 53 | return skipOSCSequence(s, i) |
| 54 | case '(', ')': |
| 55 | // G0/G1 character set selection: \x1b(char or \x1b)char |
| 56 | i += 2 // Skip ESC and ( or ) |
| 57 | if i < len(s) { |
| 58 | i++ // Skip the charset character |
| 59 | } |
| 60 | return i |
| 61 | case '=', '>', 'c': |
| 62 | // Application keypad, normal keypad, or reset: 2-char sequences |
| 63 | return i + 2 |
| 64 | default: |
| 65 | // Other 2-character escape sequences (\x1b7, \x1b8, \x1bD, etc.) |
| 66 | if s[i+1] >= '0' && s[i+1] <= '~' { |
| 67 | return i + 2 |
| 68 | } |
| 69 | // Invalid or incomplete escape sequence, skip only ESC |
| 70 | return i + 1 |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // skipCSISequence advances past a CSI sequence (\x1b[...final_char). |
| 75 | // Parameters are in range 0x30-0x3F, intermediate chars 0x20-0x2F, final 0x40-0x7E. |
no test coverage detected