~poldi1405/go-ansi

ref: 5d3db1d715a4ab8b00dda60b9b87054a4146c1aa go-ansi/colorsfg.go -rw-r--r-- 4.8 KiB
5d3db1d7 — Moritz Poldrack added support for NO_COLOR 1 year, 1 month ago
                                                                                
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
package ansi

import "fmt"

// Black wraps the content in ANSI codes to make its foreground color black
func Black(content ...interface{}) string {
	return SetBlack() + fmt.Sprint(content...) + UnsetBlack()
}

// SetBlack sets the foreground color to black
func SetBlack() string {
	if nocolorIsSet {
		return ""
	}
	return escape + blackfg + set
}

// UnsetBlack resets the foreground color from black to default.
func UnsetBlack() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Red wraps the content in ANSI codes to make its foreground color red
func Red(content ...interface{}) string {
	return SetRed() + fmt.Sprint(content...) + UnsetRed()
}

// SetRed sets the foreground color to red
func SetRed() string {
	if nocolorIsSet {
		return ""
	}
	return escape + redfg + set
}

// UnsetRed resets the foreground color from red to default.
func UnsetRed() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Green wraps the content in ANSI codes to make its foreground color green
func Green(content ...interface{}) string {
	return SetGreen() + fmt.Sprint(content...) + UnsetGreen()
}

// SetGreen sets the foreground color to green
func SetGreen() string {
	if nocolorIsSet {
		return ""
	}
	return escape + greenfg + set
}

// UnsetGreen resets the foreground color from green to default.
func UnsetGreen() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Yellow wraps the content in ANSI codes to make its foreground color yellow
func Yellow(content ...interface{}) string {
	return SetYellow() + fmt.Sprint(content...) + UnsetYellow()
}

// SetYellow sets the foreground color to yellow
func SetYellow() string {
	if nocolorIsSet {
		return ""
	}
	return escape + yellowfg + set
}

// UnsetYellow resets the foreground color from yellow to default.
func UnsetYellow() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Blue wraps the content in ANSI codes to make its foreground color blue
func Blue(content ...interface{}) string {
	return SetBlue() + fmt.Sprint(content...) + UnsetBlue()
}

// SetBlue sets the foreground color to blue
func SetBlue() string {
	if nocolorIsSet {
		return ""
	}
	return escape + bluefg + set
}

// UnsetBlue resets the foreground color from blue to default.
func UnsetBlue() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Magenta wraps the content in ANSI codes to make its foreground color magenta
func Magenta(content ...interface{}) string {
	return SetMagenta() + fmt.Sprint(content...) + UnsetMagenta()
}

// SetMagenta sets the foreground color to magenta
func SetMagenta() string {
	if nocolorIsSet {
		return ""
	}
	return escape + magentafg + set
}

// UnsetMagenta resets the foreground color from magenta to default.
func UnsetMagenta() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Cyan wraps the content in ANSI codes to make its foreground color cyan
func Cyan(content ...interface{}) string {
	return SetCyan() + fmt.Sprint(content...) + UnsetCyan()
}

// SetCyan sets the foreground color to cyan
func SetCyan() string {
	if nocolorIsSet {
		return ""
	}
	return escape + cyanfg + set
}

// UnsetCyan resets the foreground color from cyan to default.
func UnsetCyan() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// White wraps the content in ANSI codes to make its foreground color white
func White(content ...interface{}) string {
	return SetWhite() + fmt.Sprint(content...) + UnsetWhite()
}

// SetWhite sets the foreground color to white
func SetWhite() string {
	if nocolorIsSet {
		return ""
	}
	return escape + whitefg + set
}

// UnsetWhite resets the foreground color from white to default.
func UnsetWhite() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// Color256 sets a Term256 color that is applied to the provided text
func Color256(color int, content ...interface{}) string {
	return SetColor256(color) + fmt.Sprint(content...) + UnsetColor256()
}

// SetColor256 writes the following text on the specified term256 color
func SetColor256(color int) string {
	if nocolorIsSet {
		return ""
	}
	return escape + fmt.Sprintf(fg256, color) + set
}

// UnsetColor256 resets the color
func UnsetColor256() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}

// ColorTrue sets a RGB-Color that is set as the background color, writes the
func ColorTrue(r, g, b int, content ...interface{}) string {
	return SetColorTrue(r, g, b) + fmt.Sprint(content...) + UnsetColorTrue()
}

// SetColorTrue sets a RGB-Color for the font
func SetColorTrue(r, g, b int) string {
	if nocolorIsSet {
		return ""
	}
	return escape + fmt.Sprintf(fgtrue, r, g, b) + set
}

// UnsetColorTrue removes the RGB-color
func UnsetColorTrue() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetfg + set
}