-
Notifications
You must be signed in to change notification settings - Fork 13
/
colorstring.go
110 lines (88 loc) · 2.26 KB
/
colorstring.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
package colorstring
import (
"fmt"
)
// Color ...
// ANSI color escape sequences
type Color string
const (
blackColor Color = "\x1b[30;1m"
redColor Color = "\x1b[31;1m"
greenColor Color = "\x1b[32;1m"
yellowColor Color = "\x1b[33;1m"
blueColor Color = "\x1b[34;1m"
magentaColor Color = "\x1b[35;1m"
cyanColor Color = "\x1b[36;1m"
resetColor Color = "\x1b[0m"
)
// ColorFunc ...
type ColorFunc func(a ...interface{}) string
func addColor(color Color, msg string) string {
return string(color) + msg + string(resetColor)
}
// NoColor ...
func NoColor(a ...interface{}) string {
return fmt.Sprint(a...)
}
// Black ...
func Black(a ...interface{}) string {
return addColor(blackColor, fmt.Sprint(a...))
}
// Red ...
func Red(a ...interface{}) string {
return addColor(redColor, fmt.Sprint(a...))
}
// Green ...
func Green(a ...interface{}) string {
return addColor(greenColor, fmt.Sprint(a...))
}
// Yellow ...
func Yellow(a ...interface{}) string {
return addColor(yellowColor, fmt.Sprint(a...))
}
// Blue ...
func Blue(a ...interface{}) string {
return addColor(blueColor, fmt.Sprint(a...))
}
// Magenta ...
func Magenta(a ...interface{}) string {
return addColor(magentaColor, fmt.Sprint(a...))
}
// Cyan ...
func Cyan(a ...interface{}) string {
return addColor(cyanColor, fmt.Sprint(a...))
}
// ColorfFunc ...
type ColorfFunc func(format string, a ...interface{}) string
// NoColorf ...
func NoColorf(format string, a ...interface{}) string {
return NoColor(fmt.Sprintf(format, a...))
}
// Blackf ...
func Blackf(format string, a ...interface{}) string {
return Black(fmt.Sprintf(format, a...))
}
// Redf ...
func Redf(format string, a ...interface{}) string {
return Red(fmt.Sprintf(format, a...))
}
// Greenf ...
func Greenf(format string, a ...interface{}) string {
return Green(fmt.Sprintf(format, a...))
}
// Yellowf ...
func Yellowf(format string, a ...interface{}) string {
return Yellow(fmt.Sprintf(format, a...))
}
// Bluef ...
func Bluef(format string, a ...interface{}) string {
return Blue(fmt.Sprintf(format, a...))
}
// Magentaf ...
func Magentaf(format string, a ...interface{}) string {
return Magenta(fmt.Sprintf(format, a...))
}
// Cyanf ...
func Cyanf(format string, a ...interface{}) string {
return Cyan(fmt.Sprintf(format, a...))
}