Bläddra i källkod

Fixed possible issue with color text words.

I now only switch the first 3 chars (if there are > 3).
Steve Thielemann 3 år sedan
förälder
incheckning
c346b51965
1 ändrade filer med 15 tillägg och 11 borttagningar
  1. 15 11
      door/color.go

+ 15 - 11
door/color.go

@@ -36,8 +36,12 @@ func ColorText(color string) string {
 
 	parts := strings.Fields(strings.ToUpper(color))
 	for _, part := range parts {
+		if len(part) > 3 {
+			part = part[:3]
+		}
+
 		switch part {
-		case "BLACK", "BLA":
+		case "BLA":
 			if bg {
 				result = append(result, 40)
 			} else {
@@ -51,65 +55,65 @@ func ColorText(color string) string {
 				result = append(result, 31)
 			}
 
-		case "GREEN", "GRE":
+		case "GRE":
 			if bg {
 				result = append(result, 42)
 			} else {
 				result = append(result, 32)
 			}
 
-		case "BROWN", "BRO":
+		case "BRO":
 			if bg {
 				result = append(result, 43)
 			} else {
 				result = append(result, 33)
 			}
 
-		case "YELLOW", "YEL":
+		case "YEL":
 			if bg {
 				result = append(result, 43)
 			} else {
 				result = append(result, 33)
 			}
 
-		case "BLUE", "BLU":
+		case "BLU":
 			if bg {
 				result = append(result, 44)
 			} else {
 				result = append(result, 34)
 			}
 
-		case "MAGENTA", "MAG":
+		case "MAG":
 			if bg {
 				result = append(result, 45)
 			} else {
 				result = append(result, 35)
 			}
 
-		case "CYAN", "CYA":
+		case "CYA":
 			if bg {
 				result = append(result, 46)
 			} else {
 				result = append(result, 36)
 			}
 
-		case "WHITE", "WHI":
+		case "WHI":
 			if bg {
 				result = append(result, 47)
 			} else {
 				result = append(result, 37)
 			}
 
-		case "BOLD", "BOL", "BRIGHT", "BRI":
+		case "BOL", "BRI":
 			result = append(result, 1)
 
 		case "ON":
 			bg = true
 
-		case "BLINK", "BLI":
+		case "BLI":
 			result = append(result, 5)
 
-		case "INVERT", "INVERSE", "INV":
+		case "INV":
 			result = append(result, 7)
 		default:
 			fmt.Println("ColorText Unknown:", part)