-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
color.go
354 lines (320 loc) · 11.9 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package color
import "fmt"
var (
Reset = "\033[0m"
/////////////
// Special //
/////////////
Bold = "\033[1m"
Underline = "\033[4m"
/////////////////
// Text colors //
/////////////////
Black = "\033[30m"
Red = "\033[31m"
Green = "\033[32m"
Yellow = "\033[33m"
Blue = "\033[34m"
Purple = "\033[35m"
Cyan = "\033[36m"
Gray = "\033[37m"
White = "\033[97m"
///////////////////////
// Background colors //
///////////////////////
BlackBackground = "\033[40m"
RedBackground = "\033[41m"
GreenBackground = "\033[42m"
YellowBackground = "\033[43m"
BlueBackground = "\033[44m"
PurpleBackground = "\033[45m"
CyanBackground = "\033[46m"
GrayBackground = "\033[47m"
WhiteBackground = "\033[107m"
)
var (
enabled = true
)
// Toggle enables or disables color output
//
// Note that this does not apply if you are coloring by concatenating strings with color variables directly (e.g. color.Red+"Hello"+color.Reset).
// Enabling/disabling coloring only applies to all functions (Colorize, Ize, With, InRed, OverRed, etc.)
func Toggle(enable bool) {
enabled = enable
}
// Colorize wraps a given message in a given color.
//
// Example:
//
// println(color.Colorize(color.Red, "This is red"))
func Colorize(color string, s any) string {
switch s := s.(type) {
case string:
if !enabled {
return s
}
return color + s + Reset
default:
if !enabled {
return fmt.Sprint(s)
}
return color + fmt.Sprint(s) + Reset
}
}
// Ize is an alias for the Colorize function
//
// Example:
//
// println(color.Ize(color.Red, "This is red"))
func Ize(color string, s any) string {
return Colorize(color, s)
}
// With is an alias for the Colorize function
//
// Example:
//
// println(color.With(color.Red, "This is red"))
func With(color string, s any) string {
return Colorize(color, s)
}
// InBold wraps the given string s in Bold
//
// Example:
//
// println(color.InBold("This is bold"))
func InBold(s any) string {
return Colorize(Bold, s)
}
// InUnderline wraps the given string s in Underline
//
// Example:
//
// println(color.InUnderline("This is underlined"))
func InUnderline(s any) string {
return Colorize(Underline, s)
}
// InBlack wraps the given string s in Black
//
// Example:
//
// println(color.InBlack("This is black"))
func InBlack(s any) string {
return Colorize(Black, s)
}
// InRed wraps the given string s in Red
//
// Example:
//
// println(color.InRed("This is red"))
func InRed(s any) string {
return Colorize(Red, s)
}
// InGreen wraps the given string s in Green
//
// Example:
//
// println(color.InGreen("This is green"))
func InGreen(s any) string {
return Colorize(Green, s)
}
// InYellow wraps the given string s in Yellow
//
// Example:
//
// println(color.InYellow("This is yellow"))
func InYellow(s any) string {
return Colorize(Yellow, s)
}
// InBlue wraps the given string s in Blue
//
// Example:
//
// println(color.InBlue("This is blue"))
func InBlue(s any) string {
return Colorize(Blue, s)
}
// InPurple wraps the given string s in Purple
//
// Example:
//
// println(color.InPurple("This is purple"))
func InPurple(s any) string {
return Colorize(Purple, s)
}
// InCyan wraps the given string s in Cyan
//
// Example:
//
// println(color.InCyan("This is cyan"))
func InCyan(s any) string {
return Colorize(Cyan, s)
}
// InGray wraps the given string s in Gray
//
// Example:
//
// println(color.InGray("This is gray"))
func InGray(s any) string {
return Colorize(Gray, s)
}
// InWhite wraps the given string s in White
//
// Example:
//
// println(color.InWhite("This is white"))
func InWhite(s any) string {
return Colorize(White, s)
}
// OverBlack wraps the given string s in BlackBackground
//
// Example:
//
// println(color.OverBlack("This is over black"))
func OverBlack(s any) string {
return Colorize(BlackBackground, s)
}
// OverRed wraps the given string s in RedBackground
//
// Example:
//
// println(color.OverRed("This is over red"))
func OverRed(s any) string {
return Colorize(RedBackground, s)
}
// OverGreen wraps the given string s in GreenBackground
//
// Example:
//
// println(color.OverGreen("This is over green"))
func OverGreen(s any) string {
return Colorize(GreenBackground, s)
}
// OverYellow wraps the given string s in YellowBackground
//
// Example:
//
// println(color.OverYellow("This is over yellow"))
func OverYellow(s any) string {
return Colorize(YellowBackground, s)
}
// OverBlue wraps the given string s in BlueBackground
//
// Example:
//
// println(color.OverBlue("This is over blue"))
func OverBlue(s any) string {
return Colorize(BlueBackground, s)
}
// OverPurple wraps the given string s in PurpleBackground
//
// Example:
//
// println(color.OverPurple("This is over purple"))
func OverPurple(s any) string {
return Colorize(PurpleBackground, s)
}
// OverCyan wraps the given string s in CyanBackground
//
// Example:
//
// println(color.OverCyan("This is over cyan"))
func OverCyan(s any) string {
return Colorize(CyanBackground, s)
}
// OverGray wraps the given string s in GrayBackground
//
// Example:
//
// println(color.OverGray("This is over gray"))
func OverGray(s any) string {
return Colorize(GrayBackground, s)
}
// OverWhite wraps the given string s in WhiteBackground
//
// Example:
//
// println(color.OverWhite("This is over white"))
func OverWhite(s any) string {
return Colorize(WhiteBackground, s)
}
func InBlackOverBlack(s any) string { return Colorize(Black+BlackBackground, s) }
func InBlackOverRed(s any) string { return Colorize(Black+RedBackground, s) }
func InBlackOverGreen(s any) string { return Colorize(Black+GreenBackground, s) }
func InBlackOverYellow(s any) string { return Colorize(Black+YellowBackground, s) }
func InBlackOverBlue(s any) string { return Colorize(Black+BlueBackground, s) }
func InBlackOverPurple(s any) string { return Colorize(Black+PurpleBackground, s) }
func InBlackOverCyan(s any) string { return Colorize(Black+CyanBackground, s) }
func InBlackOverGray(s any) string { return Colorize(Black+GrayBackground, s) }
func InBlackOverWhite(s any) string { return Colorize(Black+WhiteBackground, s) }
func InRedOverBlack(s any) string { return Colorize(Red+BlackBackground, s) }
func InRedOverRed(s any) string { return Colorize(Red+RedBackground, s) }
func InRedOverGreen(s any) string { return Colorize(Red+GreenBackground, s) }
func InRedOverYellow(s any) string { return Colorize(Red+YellowBackground, s) }
func InRedOverBlue(s any) string { return Colorize(Red+BlueBackground, s) }
func InRedOverPurple(s any) string { return Colorize(Red+PurpleBackground, s) }
func InRedOverCyan(s any) string { return Colorize(Red+CyanBackground, s) }
func InRedOverGray(s any) string { return Colorize(Red+GrayBackground, s) }
func InRedOverWhite(s any) string { return Colorize(Red+WhiteBackground, s) }
func InGreenOverBlack(s any) string { return Colorize(Green+BlackBackground, s) }
func InGreenOverRed(s any) string { return Colorize(Green+RedBackground, s) }
func InGreenOverGreen(s any) string { return Colorize(Green+GreenBackground, s) }
func InGreenOverYellow(s any) string { return Colorize(Green+YellowBackground, s) }
func InGreenOverBlue(s any) string { return Colorize(Green+BlueBackground, s) }
func InGreenOverPurple(s any) string { return Colorize(Green+PurpleBackground, s) }
func InGreenOverCyan(s any) string { return Colorize(Green+CyanBackground, s) }
func InGreenOverGray(s any) string { return Colorize(Green+GrayBackground, s) }
func InGreenOverWhite(s any) string { return Colorize(Green+WhiteBackground, s) }
func InYellowOverBlack(s any) string { return Colorize(Yellow+BlackBackground, s) }
func InYellowOverRed(s any) string { return Colorize(Yellow+RedBackground, s) }
func InYellowOverGreen(s any) string { return Colorize(Yellow+GreenBackground, s) }
func InYellowOverYellow(s any) string { return Colorize(Yellow+YellowBackground, s) }
func InYellowOverBlue(s any) string { return Colorize(Yellow+BlueBackground, s) }
func InYellowOverPurple(s any) string { return Colorize(Yellow+PurpleBackground, s) }
func InYellowOverCyan(s any) string { return Colorize(Yellow+CyanBackground, s) }
func InYellowOverGray(s any) string { return Colorize(Yellow+GrayBackground, s) }
func InYellowOverWhite(s any) string { return Colorize(Yellow+WhiteBackground, s) }
func InBlueOverBlack(s any) string { return Colorize(Blue+BlackBackground, s) }
func InBlueOverRed(s any) string { return Colorize(Blue+RedBackground, s) }
func InBlueOverGreen(s any) string { return Colorize(Blue+GreenBackground, s) }
func InBlueOverYellow(s any) string { return Colorize(Blue+YellowBackground, s) }
func InBlueOverBlue(s any) string { return Colorize(Blue+BlueBackground, s) }
func InBlueOverPurple(s any) string { return Colorize(Blue+PurpleBackground, s) }
func InBlueOverCyan(s any) string { return Colorize(Blue+CyanBackground, s) }
func InBlueOverGray(s any) string { return Colorize(Blue+GrayBackground, s) }
func InBlueOverWhite(s any) string { return Colorize(Blue+WhiteBackground, s) }
func InPurpleOverBlack(s any) string { return Colorize(Purple+BlackBackground, s) }
func InPurpleOverRed(s any) string { return Colorize(Purple+RedBackground, s) }
func InPurpleOverGreen(s any) string { return Colorize(Purple+GreenBackground, s) }
func InPurpleOverYellow(s any) string { return Colorize(Purple+YellowBackground, s) }
func InPurpleOverBlue(s any) string { return Colorize(Purple+BlueBackground, s) }
func InPurpleOverPurple(s any) string { return Colorize(Purple+PurpleBackground, s) }
func InPurpleOverCyan(s any) string { return Colorize(Purple+CyanBackground, s) }
func InPurpleOverGray(s any) string { return Colorize(Purple+GrayBackground, s) }
func InPurpleOverWhite(s any) string { return Colorize(Purple+WhiteBackground, s) }
func InCyanOverBlack(s any) string { return Colorize(Cyan+BlackBackground, s) }
func InCyanOverRed(s any) string { return Colorize(Cyan+RedBackground, s) }
func InCyanOverGreen(s any) string { return Colorize(Cyan+GreenBackground, s) }
func InCyanOverYellow(s any) string { return Colorize(Cyan+YellowBackground, s) }
func InCyanOverBlue(s any) string { return Colorize(Cyan+BlueBackground, s) }
func InCyanOverPurple(s any) string { return Colorize(Cyan+PurpleBackground, s) }
func InCyanOverCyan(s any) string { return Colorize(Cyan+CyanBackground, s) }
func InCyanOverGray(s any) string { return Colorize(Cyan+GrayBackground, s) }
func InCyanOverWhite(s any) string { return Colorize(Cyan+WhiteBackground, s) }
func InGrayOverBlack(s any) string { return Colorize(Gray+BlackBackground, s) }
func InGrayOverRed(s any) string { return Colorize(Gray+RedBackground, s) }
func InGrayOverGreen(s any) string { return Colorize(Gray+GreenBackground, s) }
func InGrayOverYellow(s any) string { return Colorize(Gray+YellowBackground, s) }
func InGrayOverBlue(s any) string { return Colorize(Gray+BlueBackground, s) }
func InGrayOverPurple(s any) string { return Colorize(Gray+PurpleBackground, s) }
func InGrayOverCyan(s any) string { return Colorize(Gray+CyanBackground, s) }
func InGrayOverGray(s any) string { return Colorize(Gray+GrayBackground, s) }
func InGrayOverWhite(s any) string { return Colorize(Gray+WhiteBackground, s) }
func InWhiteOverBlack(s any) string { return Colorize(White+BlackBackground, s) }
func InWhiteOverRed(s any) string { return Colorize(White+RedBackground, s) }
func InWhiteOverGreen(s any) string { return Colorize(White+GreenBackground, s) }
func InWhiteOverYellow(s any) string { return Colorize(White+YellowBackground, s) }
func InWhiteOverBlue(s any) string { return Colorize(White+BlueBackground, s) }
func InWhiteOverPurple(s any) string { return Colorize(White+PurpleBackground, s) }
func InWhiteOverCyan(s any) string { return Colorize(White+CyanBackground, s) }
func InWhiteOverGray(s any) string { return Colorize(White+GrayBackground, s) }
func InWhiteOverWhite(s any) string { return Colorize(White+WhiteBackground, s) }