Skip to content
Myr

Ignore more ANSI escape sequences

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #2420

authored by Junegunn Choi · committed by Junegunn Choi · parent 391237f · Browse files · 1 file+5 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−5 removed

  • other:+5 added−5 removed

1 file+5 added−5 removed

modified:src/ansi.go+5 added-5 removed
101 unmodified lines
102 return -1103}104105func matchControlSequence(s string) int {106 // `\x1b[\\[()][0-9;]*[a-zA-Z@]`107 // ^ match starting here106 // `\x1b[\\[()][0-9;?]*[a-zA-Z@]`107 // ^ match starting here108 //109 i := 2 // prefix matched in nextAnsiEscapeSequence()110 for ; i < len(s) && (isNumeric(s[i]) || s[i] == ';'); i++ {110 for ; i < len(s) && (isNumeric(s[i]) || s[i] == ';' || s[i] == '?'); i++ {111 }112 if i < len(s) {113 c := s[i]114 if 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '@' {
9 unmodified lines
124125// nextAnsiEscapeSequence returns the ANSI escape sequence and is equivalent to126// calling FindStringIndex() on the below regex (which was originally used):127//128// "(?:\x1b[\\[()][0-9;]*[a-zA-Z@]|\x1b][0-9];[[:print:]]+(?:\x1b\\\\|\x07)|\x1b.|[\x0e\x0f]|.\x08)"128// "(?:\x1b[\\[()][0-9;?]*[a-zA-Z@]|\x1b][0-9];[[:print:]]+(?:\x1b\\\\|\x07)|\x1b.|[\x0e\x0f]|.\x08)"129//130func nextAnsiEscapeSequence(s string) (int, int) {131 // fast check for ANSI escape sequences132 i := 0
20 unmodified lines
153 _, n := utf8.DecodeLastRuneInString(s[:i])154 return i - n, i + 1155 }156 case '\x1b':157 // match: `\x1b[\\[()][0-9;]*[a-zA-Z@]`157 // match: `\x1b[\\[()][0-9;?]*[a-zA-Z@]`158 if i+2 < len(s) && isCtrlSeqStart(s[i+1]) {159 if j := matchControlSequence(s[i:]); j != -1 {160 return i, i + j161 }
248 unmodified lines