Skip to content

Commit 2862f05

Browse files
feat(colors): reserve magenta for controller log messages (#132)
1 parent c2018d4 commit 2862f05

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

cmd/colors_unix.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@ package cmd
44

55
import "fmt"
66

7+
const colorStringEscape = "\033[3%dm"
8+
79
// Choose an ANSI color by converting a string to an int.
10+
//
11+
// Color 5, magenta, reserved for controller log messages.
12+
//
13+
// Colors 0 and 7, black and white, are skipped because they are likely to be unreadable
14+
// against terminal backgrounds. Instead, 9, the default text color is used, likely to be the color
15+
// of the two that is readable against the terminal background.
816
func chooseColor(input string) string {
17+
if input == "INFO" {
18+
return fmt.Sprintf(colorStringEscape, 5)
19+
}
20+
921
var sum uint8
1022

1123
for _, char := range []byte(input) {
1224
sum += uint8(char)
1325
}
1426

15-
// Seven possible terminal colors
16-
color := (sum % 7) + 1
27+
// Eight possible terminal colors, but Black and White are excluded
28+
color := (sum % 6) + 1
1729

18-
if color == 7 {
30+
// Color 5 is reserved, replace it with default text color.
31+
if color == 5 {
1932
color = 9
2033
}
2134

22-
return fmt.Sprintf("\033[3%dm", color)
35+
return fmt.Sprintf(colorStringEscape, color)
2336
}

0 commit comments

Comments
 (0)