-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorstr.go
58 lines (52 loc) · 1.09 KB
/
colorstr.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
package pretty
import (
"fmt"
)
func GetRedText(text string) string {
return fmt.Sprintf("\033[1;31;40m%s\033[0m", text)
}
func GetGreenText(text string) string {
return fmt.Sprintf("\033[1;32;40m%s\033[0m", text)
}
func GetYellowText(text string) string {
return fmt.Sprintf("\033[1;33;40m%s\033[0m", text)
}
type ColorFormater struct {
Green []string
Yellow []string
Red []string
}
func (cf ColorFormater) Format(text string) string {
for _, str := range cf.Green {
if text == str {
return GetGreenText(text)
}
}
for _, str := range cf.Yellow {
if text == str {
return GetYellowText(text)
}
}
for _, str := range cf.Red {
if text == str {
return GetRedText(text)
}
}
return text
}
var BaseColorFormatter ColorFormater
func init() {
BaseColorFormatter = ColorFormater{
Green: []string{
"enabled", "up", "true", "yes", "success", "active", "ACTIVE",
"Running", "available", ":)",
},
Yellow: []string{
"SHUTOFF", "ShutDown", "Unknown",
},
Red: []string{
"disabled", "down", "false", "no", "failed", "error",
"ERROR", "unavailable", "XXX",
},
}
}