pb icon indicating copy to clipboard operation
pb copied to clipboard

[Question]: How to use more colors?

Open thep0y opened this issue 3 years ago • 1 comments

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
)

thep0y avatar May 23 '22 06:05 thep0y

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)

cheggaaa avatar Feb 01 '23 09:02 cheggaaa