-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcolor.go
More file actions
130 lines (110 loc) · 2.65 KB
/
color.go
File metadata and controls
130 lines (110 loc) · 2.65 KB
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
package devslog
type (
foregroundColor []byte
backgroundColor []byte
commonValuesColor []byte
)
type color struct {
fg foregroundColor
bg backgroundColor
}
var (
// Foreground colors
fgBlack foregroundColor = []byte("\x1b[30m")
fgRed foregroundColor = []byte("\x1b[31m")
fgGreen foregroundColor = []byte("\x1b[32m")
fgYellow foregroundColor = []byte("\x1b[33m")
fgBlue foregroundColor = []byte("\x1b[34m")
fgMagenta foregroundColor = []byte("\x1b[35m")
fgCyan foregroundColor = []byte("\x1b[36m")
fgWhite foregroundColor = []byte("\x1b[37m")
// Background colors
bgBlack backgroundColor = []byte("\x1b[40m")
bgRed backgroundColor = []byte("\x1b[41m")
bgGreen backgroundColor = []byte("\x1b[42m")
bgYellow backgroundColor = []byte("\x1b[43m")
bgBlue backgroundColor = []byte("\x1b[44m")
bgMagenta backgroundColor = []byte("\x1b[45m")
bgCyan backgroundColor = []byte("\x1b[46m")
bgWhite backgroundColor = []byte("\x1b[47m")
// Common consts
resetColor commonValuesColor = []byte("\x1b[0m")
faintColor commonValuesColor = []byte("\x1b[2m")
underlineColor commonValuesColor = []byte("\x1b[4m")
)
type Color uint
const (
UnknownColor Color = iota
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
)
var colors = []color{
{},
{fgBlack, bgBlack},
{fgRed, bgRed},
{fgGreen, bgGreen},
{fgYellow, bgYellow},
{fgBlue, bgBlue},
{fgMagenta, bgMagenta},
{fgCyan, bgCyan},
{fgWhite, bgWhite},
}
func (h *developHandler) getColor(c Color) color {
if int(c) < len(colors) {
return colors[c]
}
return colors[White]
}
// Color string foreground
func (h *developHandler) colorString(b []byte, fgColor foregroundColor) []byte {
if h.opts.NoColor {
return b
}
b = append(fgColor, b...)
b = append(b, resetColor...)
return b
}
// Color string fainted
func (h *developHandler) colorStringFainted(b []byte, fgColor foregroundColor) []byte {
if h.opts.NoColor {
return b
}
b = append(fgColor, b...)
b = append(faintColor, b...)
b = append(b, resetColor...)
return b
}
// Color string background
func (h *developHandler) colorStringBackgorund(b []byte, fgColor foregroundColor, bgColor backgroundColor) []byte {
if h.opts.NoColor {
return b
}
b = append(fgColor, b...)
b = append(bgColor, b...)
b = append(b, resetColor...)
return b
}
// Underline text
func (h *developHandler) underlineText(b []byte) []byte {
if h.opts.NoColor {
return b
}
b = append(underlineColor, b...)
b = append(b, resetColor...)
return b
}
// Fainted text
func (h *developHandler) faintedText(b []byte) []byte {
if h.opts.NoColor {
return b
}
b = append(faintColor, b...)
b = append(b, resetColor...)
return b
}