MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / stripAnsi

Function stripAnsi

internal/tui/picker_test.go:982–1002  ·  view source on GitHub ↗

stripAnsi removes ANSI escape codes from a string.

(s string)

Source from the content-addressed store, hash-verified

980
981// stripAnsi removes ANSI escape codes from a string.
982func 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}

Calls

no outgoing calls

Tested by

no test coverage detected