~poldi1405/go-ansi

ref: 5d3db1d715a4ab8b00dda60b9b87054a4146c1aa go-ansi/colorsbg.go -rw-r--r-- 5.1 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
214
215
package ansi

import "fmt"

// BlackBG wraps the content in ANSI codes to make its background color black
func BlackBG(content ...interface{}) string {
	return SetBlackBG() + fmt.Sprint(content...) + UnsetBlackBG()
}

// SetBlackBG sets the background color to black
func SetBlackBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + blackbg + set
}

// UnsetBlackBG resets the background color from black to default.
func UnsetBlackBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// RedBG wraps the content in ANSI codes to make its background color red
func RedBG(content ...interface{}) string {
	return SetRedBG() + fmt.Sprint(content...) + UnsetRedBG()
}

// SetRedBG sets the background color to red
func SetRedBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + redbg + set
}

// UnsetRedBG resets the background color from red to default.
func UnsetRedBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// GreenBG wraps the content in ANSI codes to make its background color green
func GreenBG(content ...interface{}) string {
	return SetGreenBG() + fmt.Sprint(content...) + UnsetGreenBG()
}

// SetGreenBG sets the background color to green
func SetGreenBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + greenbg + set
}

// UnsetGreenBG resets the background color from green to default.
func UnsetGreenBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// YellowBG wraps the content in ANSI codes to make its background color yellow
func YellowBG(content ...interface{}) string {
	return SetYellowBG() + fmt.Sprint(content...) + UnsetYellowBG()
}

// SetYellowBG sets the background color to yellow
func SetYellowBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + yellowbg + set
}

// UnsetYellowBG resets the background color from yellow to default.
func UnsetYellowBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// BlueBG wraps the content in ANSI codes to make its background color blue
func BlueBG(content ...interface{}) string {
	return SetBlueBG() + fmt.Sprint(content...) + UnsetBlueBG()
}

// SetBlueBG sets the background color to blue
func SetBlueBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + bluebg + set
}

// UnsetBlueBG resets the background color from blue to default.
func UnsetBlueBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// MagentaBG wraps the content in ANSI codes to make its background color magenta
func MagentaBG(content ...interface{}) string {
	return SetMagentaBG() + fmt.Sprint(content...) + UnsetMagentaBG()
}

// SetMagentaBG sets the background color to magenta
func SetMagentaBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + magentabg + set
}

// UnsetMagentaBG resets the background color from magenta to default.
func UnsetMagentaBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// CyanBG wraps the content in ANSI codes to make its background color cyan
func CyanBG(content ...interface{}) string {
	return SetCyanBG() + fmt.Sprint(content...) + UnsetCyanBG()
}

// SetCyanBG sets the background color to cyan
func SetCyanBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + cyanbg + set
}

// UnsetCyanBG resets the background color from cyan to default.
func UnsetCyanBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// WhiteBG wraps the content in ANSI codes to make its background color white
func WhiteBG(content ...interface{}) string {
	return SetWhiteBG() + fmt.Sprint(content...) + UnsetWhiteBG()
}

// SetWhiteBG sets the background color to white
func SetWhiteBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + whitebg + set
}

// UnsetWhiteBG resets the background color from white to default.
func UnsetWhiteBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// Color256BG sets a Term256 color that is applied to the provided text as the
// background color
func Color256BG(color int, content ...interface{}) string {
	return SetColor256BG(color) + fmt.Sprint(content...) + UnsetColor256BG()
}

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

// UnsetColor256BG resets the background color
func UnsetColor256BG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}

// ColorTrueBG sets a RGB-Color that is set as the background color, writes the
// text and clears the background color
func ColorTrueBG(r, g, b int, content ...interface{}) string {
	return SetColorTrueBG(r, g, b) + fmt.Sprint(content...) + UnsetColorTrueBG()
}

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

// UnsetColorTrueBG removes the RGB-background
func UnsetColorTrueBG() string {
	if nocolorIsSet {
		return ""
	}
	return escape + resetbg + set
}