@@ -163,7 +163,10 @@ func (c *Color) unset() {
163
163
Unset ()
164
164
}
165
165
166
- func (c * Color ) setWriter (w io.Writer ) * Color {
166
+ // SetWriter is used to set the SGR sequence with the given io.Writer. This is
167
+ // a low-level function, and users should use the higher-level functions, such
168
+ // as color.Fprint, color.Print, etc.
169
+ func (c * Color ) SetWriter (w io.Writer ) * Color {
167
170
if c .isNoColorSet () {
168
171
return c
169
172
}
@@ -172,7 +175,9 @@ func (c *Color) setWriter(w io.Writer) *Color {
172
175
return c
173
176
}
174
177
175
- func (c * Color ) unsetWriter (w io.Writer ) {
178
+ // UnsetWriter resets all escape attributes and clears the output with the give
179
+ // io.Writer. Usually should be called after SetWriter().
180
+ func (c * Color ) UnsetWriter (w io.Writer ) {
176
181
if c .isNoColorSet () {
177
182
return
178
183
}
@@ -197,8 +202,8 @@ func (c *Color) Add(value ...Attribute) *Color {
197
202
// On Windows, users should wrap w with colorable.NewColorable() if w is of
198
203
// type *os.File.
199
204
func (c * Color ) Fprint (w io.Writer , a ... interface {}) (n int , err error ) {
200
- c .setWriter (w )
201
- defer c .unsetWriter (w )
205
+ c .SetWriter (w )
206
+ defer c .UnsetWriter (w )
202
207
203
208
return fmt .Fprint (w , a ... )
204
209
}
@@ -220,8 +225,8 @@ func (c *Color) Print(a ...interface{}) (n int, err error) {
220
225
// On Windows, users should wrap w with colorable.NewColorable() if w is of
221
226
// type *os.File.
222
227
func (c * Color ) Fprintf (w io.Writer , format string , a ... interface {}) (n int , err error ) {
223
- c .setWriter (w )
224
- defer c .unsetWriter (w )
228
+ c .SetWriter (w )
229
+ defer c .UnsetWriter (w )
225
230
226
231
return fmt .Fprintf (w , format , a ... )
227
232
}
@@ -241,8 +246,8 @@ func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
241
246
// On Windows, users should wrap w with colorable.NewColorable() if w is of
242
247
// type *os.File.
243
248
func (c * Color ) Fprintln (w io.Writer , a ... interface {}) (n int , err error ) {
244
- c .setWriter (w )
245
- defer c .unsetWriter (w )
249
+ c .SetWriter (w )
250
+ defer c .UnsetWriter (w )
246
251
247
252
return fmt .Fprintln (w , a ... )
248
253
}
0 commit comments