-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.go
145 lines (117 loc) · 1.94 KB
/
color.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import "fmt"
const (
reset = iota
bold
fuzzy
italic
underscore
blink
fastBlink
reverse
concealed
strikethrough
)
const (
black = iota + 30
red
green
yellow
blue
pink
cyan
gray
white = 97
unknown = 999
)
var colorMap = map[int]string{
bold: "bold",
black: "black",
red: "red",
green: "green",
yellow: "yellow",
blue: "blue",
pink: "pink",
cyan: "cyan",
gray: "gray",
white: "white",
unknown: "unknown",
}
func SetColor(text string, conf, bg, color int) string {
return fmt.Sprintf("%c[%d;%d;%dm%s%c[0m", 0x1B, conf, bg, color, text, 0x1B)
}
func Bold(s string) string {
return SetColor(s, 0, 0, bold)
}
func Black(s string) string {
return SetColor(s, 0, 0, black)
}
func Red(s string) string {
return SetColor(s, 0, 0, red)
}
func Green(s string) string {
return SetColor(s, 0, 0, green)
}
func Yellow(s string) string {
return SetColor(s, 0, 0, yellow)
}
func Blue(s string) string {
return SetColor(s, 0, 0, blue)
}
func Pink(s string) string {
return SetColor(s, 0, 0, pink)
}
func Cyan(s string) string {
return SetColor(s, 0, 0, cyan)
}
func Gray(s string) string {
return SetColor(s, 0, 0, gray)
}
func White(s string) string {
return SetColor(s, 0, 0, white)
}
func PrintBold(s string) {
println(Bold(s))
}
func PrintBlack(s string) {
println(Black(s))
}
func PrintRed(s string) {
println(Red(s))
}
func PrintGreen(s string) {
println(Green(s))
}
func PrintYellow(s string) {
println(Yellow(s))
}
func PrintBlue(s string) {
println(Blue(s))
}
func PrintPink(s string) {
println(Pink(s))
}
func PrintCyan(s string) {
println(Cyan(s))
}
func PrintGray(s string) {
println(Gray(s))
}
func PrintWhite(s string) {
println(White(s))
}
func codeReason(code int) string {
v, ok := colorMap[code]
if !ok {
v = colorMap[unknown]
}
return v
}
func colorToCode(s string) int {
for k := range colorMap {
if colorMap[k] == s {
return k
}
}
return unknown
}