Skip to content

Conversation

@polymorcodeus
Copy link

Added OptionSetCustomColorCodes to pass in custom colors to color string - is ignored if not set.. Leverages colorstring.Colorize to customize progress bar to fit my 80s neon vibe. Doesn't appear as though there are any tests for ColorCodes.

Example Usage:

neonColors := map[string]string{
    "cyan":  "36",
    "pink":  "38;2;255;95;175",
    "reset": "0",
}

bar := progressbar.NewOptions(1000,
    progressbar.OptionSetWriter(ansi.NewAnsiStdout()), //you should install "github.com/k0kubun/go-ansi"
    progressbar.OptionEnableColorCodes(true),
    progressbar.OptionSetCustomColorCodes(neonColors),
    progressbar.OptionShowBytes(true),
    progressbar.OptionSetWidth(15),
    progressbar.OptionSetDescription("[cyan][1/3][reset] Writing moshable file..."),
    progressbar.OptionSetTheme(progressbar.Theme{
        Saucer:        "[pink]=[reset]",
        SaucerHead:    "[pink]>[reset]",
        SaucerPadding: " ",
        BarStart:      "[",
        BarEnd:        "]",
    }))
for i := 0; i < 1000; i++ {
    bar.Add(1)
    time.Sleep(5 * time.Millisecond)
}

Additionally:
Removed unused colorize bool from func getStringWidth as it doesn't appear to be used anymore.

@schollz schollz merged commit dae95ef into schollz:main Dec 26, 2025
@polymorcodeus polymorcodeus deleted the mart1082/optsetcustomcolor branch December 27, 2025 02:30
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

Successfully merging this pull request may close these issues.

2 participants