package door import ( "fmt" "strings" ) func Color(arg ...int) string { var result string = "\x1b[" for i := range arg { result += fmt.Sprintf("%d;", arg[i]) } result = result[:len(result)-1] result += "m" return result } func ColorText(color string) string { // split on spaces, uppercase, match first 3 letter var result []int var bg bool result = append(result, 0) parts := strings.Fields(strings.ToUpper(color)) for _, part := range parts { switch part { case "BLACK", "BLA": if bg { result = append(result, 40) } else { result = append(result, 30) } case "RED": if bg { result = append(result, 41) } else { result = append(result, 31) } case "GREEN", "GRE": if bg { result = append(result, 42) } else { result = append(result, 32) } case "BROWN", "BRO": if bg { result = append(result, 43) } else { result = append(result, 33) } case "YELLOW", "YEL": if bg { result = append(result, 43) } else { result = append(result, 33) } case "BLUE", "BLU": if bg { result = append(result, 44) } else { result = append(result, 34) } case "MAGENTA", "MAG": if bg { result = append(result, 45) } else { result = append(result, 35) } case "CYAN", "CYA": if bg { result = append(result, 46) } else { result = append(result, 36) } case "WHITE", "WHI": if bg { result = append(result, 47) } else { result = append(result, 37) } case "BOLD", "BOL", "BRIGHT", "BRI": result = append(result, 1) case "ON": bg = true case "BLINK", "BLI": result = append(result, 5) case "INVERT", "INVERSE", "INV": result = append(result, 7) default: fmt.Println("ColorText Unknown:", part) } } // fmt.Println("ColorText:", result) return Color(result...) }