Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to use more colors? #193

Open
thep0y opened this issue May 23, 2022 · 1 comment
Open

[Question]: How to use more colors? #193

thep0y opened this issue May 23, 2022 · 1 comment

Comments

@thep0y
Copy link

thep0y commented May 23, 2022

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
)
@cheggaaa
Copy link
Owner

cheggaaa commented Feb 1, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants