Closed pszxzsd closed 8 years ago
That is not because of a problem with SprintFunc
, but because cyan("foo")
returns a string with 5 bytes. Or put differently: fmt.Printf
does not take the color codes into account when formatting the string.
I suggest using SprintfFunc
to format the string before the color codes are added:
cyan := color.New(color.FgCyan).SprintfFunc()
fmt.Println(cyan("%-5v", "foo") + "bar")
Thanks @mgeisler for the clarification. Closing as this is the indented way. There is not much we can do. @pszxzsd I recommend to use it like @mgeisler recommended. Thanks.
e.g.:
should print "foo bar" (with 2 spaces) but prints "foobar"