@@ -269,7 +269,7 @@ func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
269269// On Windows, users should wrap w with colorable.NewColorable() if w is of
270270// type *os.File.
271271func (c * Color ) Fprintln (w io.Writer , a ... interface {}) (n int , err error ) {
272- return fmt .Fprintln (w , c .wrap (fmt . Sprint (a ... )))
272+ return fmt .Fprintln (w , c .wrap (sprintln (a ... )))
273273}
274274
275275// Println formats using the default formats for its operands and writes to
@@ -278,7 +278,7 @@ func (c *Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
278278// encountered. This is the standard fmt.Print() method wrapped with the given
279279// color.
280280func (c * Color ) Println (a ... interface {}) (n int , err error ) {
281- return fmt .Fprintln (Output , c .wrap (fmt . Sprint (a ... )))
281+ return fmt .Fprintln (Output , c .wrap (sprintln (a ... )))
282282}
283283
284284// Sprint is just like Print, but returns a string instead of printing it.
@@ -288,7 +288,7 @@ func (c *Color) Sprint(a ...interface{}) string {
288288
289289// Sprintln is just like Println, but returns a string instead of printing it.
290290func (c * Color ) Sprintln (a ... interface {}) string {
291- return fmt . Sprintln ( c . Sprint ( a ... ))
291+ return c . wrap ( sprintln ( a ... )) + " \n "
292292}
293293
294294// Sprintf is just like Printf, but returns a string instead of printing it.
@@ -370,7 +370,7 @@ func (c *Color) SprintfFunc() func(format string, a ...interface{}) string {
370370// string. Windows users should use this in conjunction with color.Output.
371371func (c * Color ) SprintlnFunc () func (a ... interface {}) string {
372372 return func (a ... interface {}) string {
373- return fmt . Sprintln ( c . Sprint ( a ... ))
373+ return c . wrap ( sprintln ( a ... )) + " \n "
374374 }
375375}
376376
@@ -648,3 +648,8 @@ func HiCyanString(format string, a ...interface{}) string { return colorString(f
648648func HiWhiteString (format string , a ... interface {}) string {
649649 return colorString (format , FgHiWhite , a ... )
650650}
651+
652+ // sprintln is a helper function to format a string with fmt.Sprintln and trim the trailing newline.
653+ func sprintln (a ... interface {}) string {
654+ return strings .TrimSuffix (fmt .Sprintln (a ... ), "\n " )
655+ }
0 commit comments