File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -247,6 +247,21 @@ func (c *Color) Println(a ...interface{}) (n int, err error) {
247247 return fmt .Fprintln (Output , a ... )
248248}
249249
250+ // Sprint is just like Print, but returns a string instead of printing it.
251+ func (c * Color ) Sprint (a ... interface {}) string {
252+ return c .wrap (fmt .Sprint (a ... ))
253+ }
254+
255+ // Sprintln is just like Println, but returns a string instead of printing it.
256+ func (c * Color ) Sprintln (a ... interface {}) string {
257+ return c .wrap (fmt .Sprintln (a ... ))
258+ }
259+
260+ // Sprintf is just like Printf, but returns a string instead of printing it.
261+ func (c * Color ) Sprintf (format string , a ... interface {}) string {
262+ return c .wrap (fmt .Sprintf (format , a ... ))
263+ }
264+
250265// FprintFunc returns a new function that prints the passed arguments as
251266// colorized with color.Fprint().
252267func (c * Color ) FprintFunc () func (w io.Writer , a ... interface {}) {
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ func TestColor(t *testing.T) {
5454 t .Errorf ("Expecting %s, got '%s'\n " , escapedForm , scannedLine )
5555 }
5656 }
57+
58+ for _ , c := range testColors {
59+ line := New (c .code ).Sprintf ("%s" , c .text )
60+ scannedLine := fmt .Sprintf ("%q" , line )
61+ colored := fmt .Sprintf ("\x1b [%dm%s\x1b [0m" , c .code , c .text )
62+ escapedForm := fmt .Sprintf ("%q" , colored )
63+
64+ fmt .Printf ("%s\t : %s\n " , c .text , line )
65+
66+ if scannedLine != escapedForm {
67+ t .Errorf ("Expecting %s, got '%s'\n " , escapedForm , scannedLine )
68+ }
69+ }
5770}
5871
5972func TestColorEquals (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments