pb
pb copied to clipboard
[Question]: How to use more colors?
Some colors are defined in defaultTemplateFuncs, but these are only some of the colors in the color package, how to use more colors quickly?
// Foreground text colors
const (
FgBlack Attribute = iota + 30
FgRed
FgGreen
FgYellow
FgBlue
FgMagenta
FgCyan
FgWhite
)
// Foreground Hi-Intensity text colors
const (
FgHiBlack Attribute = iota + 90
FgHiRed
FgHiGreen
FgHiYellow
FgHiBlue
FgHiMagenta
FgHiCyan
FgHiWhite
)
You can register a new pb.Element
pb.RegisterElement("myColor", pb.ElementFunc(func(state *pb.State, args ...string) string {
for _, arg := range args {
return color.New(color.BgHiGreen).Sprint(arg)
}
return ""
}), false)
tmpl := `{{counters . | myColor .}} {{bar . }} {{percent . }} {{ myColor . "one" }}`
bar := pb.ProgressBarTemplate(tmpl)