stripAnsi removes ANSI escape codes from a string.
(s string)
| 980 | |
| 981 | // stripAnsi removes ANSI escape codes from a string. |
| 982 | func stripAnsi(s string) string { |
| 983 | var result []byte |
| 984 | i := 0 |
| 985 | for i < len(s) { |
| 986 | if s[i] == '\x1b' && i+1 < len(s) && s[i+1] == '[' { |
| 987 | // Skip to end of escape sequence |
| 988 | j := i + 2 |
| 989 | for j < len(s) && !((s[j] >= 'A' && s[j] <= 'Z') || (s[j] >= 'a' && s[j] <= 'z')) { |
| 990 | j++ |
| 991 | } |
| 992 | if j < len(s) { |
| 993 | j++ // skip the final letter |
| 994 | } |
| 995 | i = j |
| 996 | } else { |
| 997 | result = append(result, s[i]) |
| 998 | i++ |
| 999 | } |
| 1000 | } |
| 1001 | return string(result) |
| 1002 | } |
no outgoing calls
no test coverage detected