Moonshark/utils/color/color.go
2025-05-10 13:02:09 -05:00

47 lines
713 B
Go

package color
// ANSI color codes
const (
Reset = "\033[0m"
Red = "\033[31m"
Green = "\033[32m"
Yellow = "\033[33m"
Blue = "\033[34m"
Purple = "\033[35m"
Cyan = "\033[36m"
White = "\033[37m"
Gray = "\033[90m"
)
// Apply adds color to text if useColors is true
func Apply(text, color string, useColors bool) string {
if useColors {
return color + text + Reset
}
return text
}
// Strip removes ANSI color codes from a string
func Strip(s string) string {
result := ""
inEscape := false
for _, c := range s {
if inEscape {
if c == 'm' {
inEscape = false
}
continue
}
if c == '\033' {
inEscape = true
continue
}
result += string(c)
}
return result
}