-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors.go
76 lines (63 loc) · 1.31 KB
/
colors.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
package debugo
import (
"time"
"github.com/fatih/color"
"golang.org/x/exp/rand"
)
var noColor = color.New(color.Reset)
var fgColors = []color.Attribute{
color.FgRed,
color.FgGreen,
color.FgYellow,
color.FgBlue,
color.FgMagenta,
color.FgCyan,
color.FgHiBlack,
color.FgHiRed,
color.FgHiGreen,
color.FgHiYellow,
color.FgHiBlue,
color.FgHiMagenta,
color.FgHiCyan,
color.FgHiWhite,
}
var bgColors = []color.Attribute{
color.BgBlack,
color.BgRed,
color.BgGreen,
color.BgYellow,
color.BgBlue,
color.BgMagenta,
color.BgCyan,
color.BgWhite,
color.BgHiBlack,
color.BgHiRed,
color.BgHiGreen,
color.BgHiYellow,
color.BgHiBlue,
color.BgHiMagenta,
color.BgHiCyan,
color.BgHiWhite,
}
// cache bgColors by namespace
var fgColorMap = make(map[string]*color.Color)
// cache fgColors by namespace
var bgColorMap = make(map[string]*color.Color)
func (l *Debugger) setRandomColor(useBg bool) {
rand.Seed(uint64(time.Now().UnixNano()))
if useBg {
if color, ok := bgColorMap[l.namespace]; ok {
l.color = color
return
}
l.color = color.New(bgColors[rand.Intn(len(bgColors))])
bgColorMap[l.namespace] = l.color
} else {
if color, ok := fgColorMap[l.namespace]; ok {
l.color = color
return
}
l.color = color.New(fgColors[rand.Intn(len(fgColors))])
fgColorMap[l.namespace] = l.color
}
}