diff --git a/go.mod b/go.mod index fa8de5bf5..aa3244cfb 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/google/go-containerregistry v0.20.2 github.com/onsi/gomega v1.34.2 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 - github.com/schollz/progressbar/v3 v3.16.0 + github.com/schollz/progressbar/v3 v3.16.1 github.com/shipwright-io/build v0.13.0 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 6094633cb..110cb1105 100644 --- a/go.sum +++ b/go.sum @@ -379,8 +379,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI= github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs= -github.com/schollz/progressbar/v3 v3.16.0 h1:+MbBim/cE9DqDb8UXRfLJ6RZdyDkXG1BDy/sWc5s0Mc= -github.com/schollz/progressbar/v3 v3.16.0/go.mod h1:lLiKjKJ9/yzc9Q8jk+sVLfxWxgXKsktvUf6TO+4Y2nw= +github.com/schollz/progressbar/v3 v3.16.1 h1:RnF1neWZFzLCoGx8yp1yF7SDl4AzNDI5y4I0aUJRrZQ= +github.com/schollz/progressbar/v3 v3.16.1/go.mod h1:I2ILR76gz5VXqYMIY/LdLecvMHDPVcQm3W/MSKi1TME= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shipwright-io/build v0.13.0 h1:UBap+Mk6P0fji/sLc3eBmDlAPWvZWE4KdSQiVUkwYEU= diff --git a/vendor/github.com/schollz/progressbar/v3/progressbar.go b/vendor/github.com/schollz/progressbar/v3/progressbar.go index d8821a137..51be10162 100644 --- a/vendor/github.com/schollz/progressbar/v3/progressbar.go +++ b/vendor/github.com/schollz/progressbar/v3/progressbar.go @@ -145,7 +145,45 @@ type Theme struct { SaucerPadding string BarStart string BarEnd string -} + + // BarStartFilled is used after the Bar starts filling, if set. Otherwise, it defaults to BarStart. + BarStartFilled string + + // BarEndFilled is used once the Bar finishes, if set. Otherwise, it defaults to BarEnd. + BarEndFilled string +} + +var ( + // ThemeDefault is given by default (if not changed with OptionSetTheme), and it looks like "|████ |". + ThemeDefault = Theme{Saucer: "█", SaucerPadding: " ", BarStart: "|", BarEnd: "|"} + + // ThemeASCII is a predefined Theme that uses ASCII symbols. It looks like "[===>...]". + // Configure it with OptionSetTheme(ThemeASCII). + ThemeASCII = Theme{ + Saucer: "=", + SaucerHead: ">", + SaucerPadding: ".", + BarStart: "[", + BarEnd: "]", + } + + // ThemeUnicode is a predefined Theme that uses Unicode characters, displaying a graphic bar. + // It looks like "" (rendering will depend on font being used). + // It requires special symbols usually found in "nerd fonts" [2], or in Fira Code [1], and other sources. + // Configure it with OptionSetTheme(ThemeUnicode). + // + // [1] https://github.com/tonsky/FiraCode + // [2] https://www.nerdfonts.com/ + ThemeUnicode = Theme{ + Saucer: "\uEE04", //  + SaucerHead: "\uEE04", //  + SaucerPadding: "\uEE01", //  + BarStart: "\uEE00", //  + BarStartFilled: "\uEE03", //  + BarEnd: "\uEE02", //  + BarEndFilled: "\uEE05", //  + } +) // Option is the type all options need to adhere to type Option func(p *ProgressBar) @@ -185,7 +223,8 @@ func OptionSpinnerCustom(spinner []string) Option { } } -// OptionSetTheme sets the elements the bar is constructed of +// OptionSetTheme sets the elements the bar is constructed with. +// There are two pre-defined themes you can use: ThemeASCII and ThemeUnicode. func OptionSetTheme(t Theme) Option { return func(p *ProgressBar) { p.config.theme = t @@ -263,7 +302,7 @@ func OptionShowIts() Option { } } -// OptionShowElapsedOnFinish will keep the display of elapsed time on finish +// OptionShowElapsedTimeOnFinish will keep the display of elapsed time on finish. func OptionShowElapsedTimeOnFinish() Option { return func(p *ProgressBar) { p.config.showElapsedTimeOnFinish = true @@ -285,7 +324,7 @@ func OptionThrottle(duration time.Duration) Option { } } -// OptionClearOnFinish will clear the bar once its finished +// OptionClearOnFinish will clear the bar once its finished. func OptionClearOnFinish() Option { return func(p *ProgressBar) { p.config.clearOnFinish = true @@ -339,8 +378,6 @@ func OptionSetMaxDetailRow(row int) Option { } } -var defaultTheme = Theme{Saucer: "█", SaucerPadding: " ", BarStart: "|", BarEnd: "|"} - // NewOptions constructs a new instance of ProgressBar, with any options you specify func NewOptions(max int, options ...Option) *ProgressBar { return NewOptions64(int64(max), options...) @@ -356,7 +393,7 @@ func NewOptions64(max int64, options ...Option) *ProgressBar { }, config: config{ writer: os.Stdout, - theme: defaultTheme, + theme: ThemeDefault, iterationString: "it", width: 40, max: max, @@ -394,14 +431,8 @@ func NewOptions64(max int64, options ...Option) *ProgressBar { } // if the render time interval attribute is set - if b.config.spinnerChangeInterval != 0 { + if b.config.spinnerChangeInterval != 0 && !b.config.invisible && b.config.ignoreLength { go func() { - if b.config.invisible { - return - } - if !b.config.ignoreLength { - return - } ticker := time.NewTicker(b.config.spinnerChangeInterval) defer ticker.Stop() for { @@ -836,10 +867,12 @@ func (p *ProgressBar) render() error { } if !p.config.useANSICodes { - // first, clear the existing progress bar - err := clearProgressBar(p.config, p.state) - if err != nil { - return err + // first, clear the existing progress bar, if not yet finished. + if !p.state.finished { + err := clearProgressBar(p.config, p.state) + if err != nil { + return err + } } } @@ -1027,6 +1060,10 @@ func renderProgressBar(c config, s *state) (int, error) { } leftBrac, rightBrac, saucer, saucerHead := "", "", "", "" + barStart, barEnd := c.theme.BarStart, c.theme.BarEnd + if s.finished && c.theme.BarEndFilled != "" { + barEnd = c.theme.BarEndFilled + } // show time prediction in "current/total" seconds format switch { @@ -1063,6 +1100,9 @@ func renderProgressBar(c config, s *state) (int, error) { c.width = width - getStringWidth(c, c.description, true) - 10 - amend - sb.Len() - len(leftBrac) - len(rightBrac) s.currentSaucerSize = int(float64(s.currentPercent) / 100.0 * float64(c.width)) } + if (s.currentSaucerSize > 0 || s.currentPercent > 0) && c.theme.BarStartFilled != "" { + barStart = c.theme.BarStartFilled + } if s.currentSaucerSize > 0 { if c.ignoreLength { saucer = strings.Repeat(c.theme.SaucerPadding, s.currentSaucerSize-1) @@ -1144,11 +1184,11 @@ func renderProgressBar(c config, s *state) (int, error) { } else if rightBrac == "" { str = fmt.Sprintf("%4d%% %s%s%s%s%s %s", s.currentPercent, - c.theme.BarStart, + barStart, saucer, saucerHead, strings.Repeat(c.theme.SaucerPadding, repeatAmount), - c.theme.BarEnd, + barEnd, sb.String()) if (s.currentPercent == 100 && c.showElapsedTimeOnFinish) || c.elapsedTime { str = fmt.Sprintf("%s [%s]", str, leftBrac) @@ -1163,11 +1203,11 @@ func renderProgressBar(c config, s *state) (int, error) { if s.currentPercent == 100 { str = fmt.Sprintf("%4d%% %s%s%s%s%s %s", s.currentPercent, - c.theme.BarStart, + barStart, saucer, saucerHead, strings.Repeat(c.theme.SaucerPadding, repeatAmount), - c.theme.BarEnd, + barEnd, sb.String()) if c.showElapsedTimeOnFinish { @@ -1182,11 +1222,11 @@ func renderProgressBar(c config, s *state) (int, error) { } else { str = fmt.Sprintf("%4d%% %s%s%s%s%s %s [%s:%s]", s.currentPercent, - c.theme.BarStart, + barStart, saucer, saucerHead, strings.Repeat(c.theme.SaucerPadding, repeatAmount), - c.theme.BarEnd, + barEnd, sb.String(), leftBrac, rightBrac) diff --git a/vendor/modules.txt b/vendor/modules.txt index 9290f9204..ff18093a3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -311,7 +311,7 @@ github.com/russross/blackfriday/v2 # github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 ## explicit; go 1.13 github.com/sabhiram/go-gitignore -# github.com/schollz/progressbar/v3 v3.16.0 +# github.com/schollz/progressbar/v3 v3.16.1 ## explicit; go 1.22 github.com/schollz/progressbar/v3 # github.com/shipwright-io/build v0.13.0