-
Notifications
You must be signed in to change notification settings - Fork 47
/
color.go
179 lines (147 loc) · 4 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
/*
Copyright (c) 2021 - Present. Blend Labs, Inc. All rights reserved
Blend Confidential - Restricted
*/
package ansi
// Black applies a given color.
func Black(text string) string {
return Apply(ColorBlack, text)
}
// Red applies a given color.
func Red(text string) string {
return Apply(ColorRed, text)
}
// Green applies a given color.
func Green(text string) string {
return Apply(ColorGreen, text)
}
// Yellow applies a given color.
func Yellow(text string) string {
return Apply(ColorYellow, text)
}
// Blue applies a given color.
func Blue(text string) string {
return Apply(ColorBlue, text)
}
// Purple applies a given color.
func Purple(text string) string {
return Apply(ColorPurple, text)
}
// Cyan applies a given color.
func Cyan(text string) string {
return Apply(ColorCyan, text)
}
// White applies a given color.
func White(text string) string {
return Apply(ColorWhite, text)
}
// LightBlack applies a given color.
func LightBlack(text string) string {
return Apply(ColorLightBlack, text)
}
// LightRed applies a given color.
func LightRed(text string) string {
return Apply(ColorLightRed, text)
}
// LightGreen applies a given color.
func LightGreen(text string) string {
return Apply(ColorLightGreen, text)
}
// LightYellow applies a given color.
func LightYellow(text string) string {
return Apply(ColorLightYellow, text)
}
// LightBlue applies a given color.
func LightBlue(text string) string {
return Apply(ColorLightBlue, text)
}
// LightPurple applies a given color.
func LightPurple(text string) string {
return Apply(ColorLightPurple, text)
}
// LightCyan applies a given color.
func LightCyan(text string) string {
return Apply(ColorLightCyan, text)
}
// LightWhite applies a given color.
func LightWhite(text string) string {
return Apply(ColorLightWhite, text)
}
// Apply applies a given color.
func Apply(colorCode Color, text string) string {
return colorCode.Normal() + text + ColorReset
}
// Bold applies a given color as bold.
func Bold(colorCode Color, text string) string {
return colorCode.Bold() + text + ColorReset
}
// Underline applies a given color as underline.
func Underline(colorCode Color, text string) string {
return colorCode.Underline() + text + ColorReset
}
// Color represents an ansi color code fragment.
type Color string
// Normal escapes the color for use in the terminal.
func (c Color) Normal() string {
return "\033[0;" + string(c)
}
// Bold escapes the color for use in the terminal as a bold color.
func (c Color) Bold() string {
return "\033[1;" + string(c)
}
// Underline escapes the color for use in the terminal as underlined color.
func (c Color) Underline() string {
return "\033[4;" + string(c)
}
// Apply applies a color to a given string.
func (c Color) Apply(text string) string {
return Apply(c, text)
}
// Utility Color Codes
const (
ColorReset = "\033[0m"
)
// Color codes
const (
ColorBlack Color = "30m"
ColorRed Color = "31m"
ColorGreen Color = "32m"
ColorYellow Color = "33m"
ColorBlue Color = "34m"
ColorPurple Color = "35m"
ColorCyan Color = "36m"
ColorWhite Color = "37m"
)
// BrightColorCodes
const (
ColorLightBlack Color = "90m"
ColorLightRed Color = "91m"
ColorLightGreen Color = "92m"
ColorLightYellow Color = "93m"
ColorLightBlue Color = "94m"
ColorLightPurple Color = "95m"
ColorLightCyan Color = "96m"
ColorLightWhite Color = "97m"
)
// BackgroundColorCodes
const (
ColorBackgroundBlack Color = "40m"
ColorBackgroundRed Color = "41m"
ColorBackgroundGreen Color = "42m"
ColorBackgroundYellow Color = "43m"
ColorBackgroundBlue Color = "44m"
ColorBackgroundPurple Color = "45m"
ColorBackgroundCyan Color = "46m"
ColorBackgroundWhite Color = "47m"
)
// BackgroundColorCodes
const (
ColorBackgroundBrightBlack Color = "100m"
ColorBackgroundBrightRed Color = "101m"
ColorBackgroundBrightGreen Color = "102m"
ColorBackgroundBrightYellow Color = "103m"
ColorBackgroundBrightBlue Color = "104m"
ColorBackgroundBrightPurple Color = "105m"
ColorBackgroundBrightCyan Color = "106m"
ColorBackgroundBrightWhite Color = "107m"
)