Commit 263f6bf06804f91ed8ab6e47420ef09ecc54b8fd

Parents: 1a39693daee87dfb20f23cf9018da3a209f2c529

From: Moritz Poldrack <ich@moritz-poldrack.de>
Date: Tue Jun 22 09:44:11 2021 +0700

removed duplicate code

		

Stats

colorsbg.go +9/-54
colorsfg.go +8/-48

Changeset

  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
diff --git a/colorsbg.go b/colorsbg.go
index c9d58e70ae6ea644957fe89afb1e6464f5da59b8..abe94cf5c9658b286cc9953fea16e83021df2c82 100644
--- a/colorsbg.go
+++ b/colorsbg.go
@@ -37,12 +37,7 @@ 	return escape + redbg + set
 }
 
 // UnsetRedBG resets the background color from red to default.
-func UnsetRedBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetRedBG func() string = UnsetBlackBG
 
 // GreenBG wraps the content in ANSI codes to make its background color green
 func GreenBG(content ...interface{}) string {
@@ -58,12 +53,7 @@ 	return escape + greenbg + set
 }
 
 // UnsetGreenBG resets the background color from green to default.
-func UnsetGreenBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetGreenBG func() string = UnsetBlackBG
 
 // YellowBG wraps the content in ANSI codes to make its background color yellow
 func YellowBG(content ...interface{}) string {
@@ -79,12 +69,7 @@ 	return escape + yellowbg + set
 }
 
 // UnsetYellowBG resets the background color from yellow to default.
-func UnsetYellowBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetYellowBG func() string = UnsetBlackBG
 
 // BlueBG wraps the content in ANSI codes to make its background color blue
 func BlueBG(content ...interface{}) string {
@@ -100,12 +85,7 @@ 	return escape + bluebg + set
 }
 
 // UnsetBlueBG resets the background color from blue to default.
-func UnsetBlueBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetBlueBG func() string = UnsetBlackBG
 
 // MagentaBG wraps the content in ANSI codes to make its background color magenta
 func MagentaBG(content ...interface{}) string {
@@ -121,12 +101,7 @@ 	return escape + magentabg + set
 }
 
 // UnsetMagentaBG resets the background color from magenta to default.
-func UnsetMagentaBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetMagentaBG func() string = UnsetBlackBG
 
 // CyanBG wraps the content in ANSI codes to make its background color cyan
 func CyanBG(content ...interface{}) string {
@@ -142,12 +117,7 @@ 	return escape + cyanbg + set
 }
 
 // UnsetCyanBG resets the background color from cyan to default.
-func UnsetCyanBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetCyanBG func() string = UnsetBlackBG
 
 // WhiteBG wraps the content in ANSI codes to make its background color white
 func WhiteBG(content ...interface{}) string {
@@ -163,12 +133,7 @@ 	return escape + whitebg + set
 }
 
 // UnsetWhiteBG resets the background color from white to default.
-func UnsetWhiteBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetWhiteBG func() string = UnsetBlackBG
 
 // Color256BG sets a Term256 color that is applied to the provided text as the
 // background color
@@ -185,12 +150,7 @@ 	return escape + fmt.Sprintf(bg256, color) + set
 }
 
 // UnsetColor256BG resets the background color
-func UnsetColor256BG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetColor256BG func() string = UnsetBlackBG
 
 // ColorTrueBG sets a RGB-Color that is set as the background color, writes the
 // text and clears the background color
@@ -207,9 +167,4 @@ 	return escape + fmt.Sprintf(bgtrue, r, g, b) + set
 }
 
 // UnsetColorTrueBG removes the RGB-background
-func UnsetColorTrueBG() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetbg + set
-}
+var UnsetColorTrueBG func() string = UnsetBlackBG
diff --git a/colorsfg.go b/colorsfg.go
index 4bc981c9c002c85b9ba61f099549edb76a6e3da5..c2cb86cd4d9e849589b512eddcbca6ba437c7a3a 100644
--- a/colorsfg.go
+++ b/colorsfg.go
@@ -29,12 +29,7 @@ 	return SetRed() + fmt.Sprint(content...) + UnsetRed()
 }
 
 // SetRed sets the foreground color to red
-func SetRed() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + redfg + set
-}
+var SetRed func() string = UnsetBlack
 
 // UnsetRed resets the foreground color from red to default.
 func UnsetRed() string {
@@ -79,12 +74,7 @@ 	return escape + yellowfg + set
 }
 
 // UnsetYellow resets the foreground color from yellow to default.
-func UnsetYellow() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetYellow func() string = UnsetBlack
 
 // Blue wraps the content in ANSI codes to make its foreground color blue
 func Blue(content ...interface{}) string {
@@ -100,12 +90,7 @@ 	return escape + bluefg + set
 }
 
 // UnsetBlue resets the foreground color from blue to default.
-func UnsetBlue() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetBlue func() string = UnsetBlack
 
 // Magenta wraps the content in ANSI codes to make its foreground color magenta
 func Magenta(content ...interface{}) string {
@@ -121,12 +106,7 @@ 	return escape + magentafg + set
 }
 
 // UnsetMagenta resets the foreground color from magenta to default.
-func UnsetMagenta() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetMagenta func() string = UnsetBlack
 
 // Cyan wraps the content in ANSI codes to make its foreground color cyan
 func Cyan(content ...interface{}) string {
@@ -142,12 +122,7 @@ 	return escape + cyanfg + set
 }
 
 // UnsetCyan resets the foreground color from cyan to default.
-func UnsetCyan() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetCyan func() string = UnsetBlack
 
 // White wraps the content in ANSI codes to make its foreground color white
 func White(content ...interface{}) string {
@@ -163,12 +138,7 @@ 	return escape + whitefg + set
 }
 
 // UnsetWhite resets the foreground color from white to default.
-func UnsetWhite() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetWhite func() string = UnsetBlack
 
 // Color256 sets a Term256 color that is applied to the provided text
 func Color256(color int, content ...interface{}) string {
@@ -184,12 +154,7 @@ 	return escape + fmt.Sprintf(fg256, color) + set
 }
 
 // UnsetColor256 resets the color
-func UnsetColor256() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetColor func() string = UnsetBlack
 
 // ColorTrue sets a RGB-Color that is set as the background color, writes the
 func ColorTrue(r, g, b int, content ...interface{}) string {
@@ -205,9 +170,4 @@ 	return escape + fmt.Sprintf(fgtrue, r, g, b) + set
 }
 
 // UnsetColorTrue removes the RGB-color
-func UnsetColorTrue() string {
-	if nocolorIsSet {
-		return ""
-	}
-	return escape + resetfg + set
-}
+var UnsetColorTrue func() string = UnsetBlack