Style.Sprintf and RGBStyle.Sprintf behave differently
harenber opened this issue · comments
I'm just learning to use your library, so please excuse me if it is written somewhere, but I couldn't find anything.
First: thanks for providing this fine library and all the useful documentation (and demos!)!
Starting to use it, I got confused. I used this piece of code:
func p(a *pterm.AreaPrinter) {
foregroundRGB := pterm.RGB{R: 0, G: 0, B: 0}
backgroundRGB := pterm.RGB{R: 255, G: 0, B: 0}
aRGBStyle := pterm.NewRGBStyle(foregroundRGB, backgroundRGB)
aStyle := pterm.NewStyle(pterm.FgBlack,pterm.BgLightRed)
for i := 0; i < 5; i++ {
if i%2 == 0 {
a.Update(aStyle.Sprintf("Current count: %d\n",i))
} else {
a.Update(aRGBStyle.Sprintf("Current count: %d\n",i))
}
time.Sleep(time.Second)
}
}
- the
astyle.Sprintf
behave like I would expect it to behave (and consistently withfmt.Sprintf
): it outputs the string with the style applied. - the
aRGBStyle.Sprintf
however, complains about a format mismatch:Current count: %!d(string=1)
and even if you change the %d into a %s (which makes no sense?), only the value ofi
is printed in the style. "Current count: " is still the default (white on black in my case). Only if you do aaRGBSyle.Sprintf("%s\n", "Current count: ", i)
(with only the%s
in the format, not%s%d
as one might expect) I got what I expected.
As said: maybe it's written somewhere, but I couldn't find the difference being mentioned in the documentation and at least IMHO it would be easier if these two Sprintf calls would behave consistently.
Thanks for reporting the issue (and thanks for the compliment)! I'll fix it. You're right, they should both behave the same.
Fixed in #622. Will be merged and released as soon as the CI is done 🚀