/
colorstr.go
47 lines (41 loc) · 1.02 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
package utility
import (
"github.com/BytemanD/easygo/pkg/stringutils"
"github.com/fatih/color"
)
type ColorFormater struct {
Green []string
Yellow []string
Red []string
}
func (cf ColorFormater) Format(text string) string {
switch {
case stringutils.ContainsString(cf.Green, text):
return color.GreenString(text)
case stringutils.ContainsString(cf.Yellow, text):
return color.YellowString(text)
case stringutils.ContainsString(cf.Red, text):
return color.RedString(text)
default:
return text
}
}
var BaseColorFormatter ColorFormater
func ColorString(text string) string {
return BaseColorFormatter.Format(text)
}
func init() {
BaseColorFormatter = ColorFormater{
Green: []string{
"enabled", "up", "true", "yes", "success", "active", "ACTIVE",
"Running", "available", ":)", ":-)", "Success", "completed",
},
Yellow: []string{
"SHUTOFF", "ShutDown", "Unknown", "in-use",
},
Red: []string{
"disabled", "down", "DOWN", "false", "no", "failed", "error",
"ERROR", "unavailable", "XXX",
},
}
}