From 7fdb52a340dc3d5e23c21cb0eb14d62aafe56b81 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 06:46:45 +0000 Subject: [PATCH] Bump github.com/schollz/progressbar/v3 from 3.8.6 to 3.9.0 Bumps [github.com/schollz/progressbar/v3](https://github.com/schollz/progressbar) from 3.8.6 to 3.9.0. - [Release notes](https://github.com/schollz/progressbar/releases) - [Commits](https://github.com/schollz/progressbar/compare/v3.8.6...v3.9.0) --- updated-dependencies: - dependency-name: github.com/schollz/progressbar/v3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../schollz/progressbar/v3/progressbar.go | 97 ++++++++++++------- vendor/modules.txt | 2 +- 4 files changed, 66 insertions(+), 39 deletions(-) diff --git a/go.mod b/go.mod index a92630634..98f895031 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/google/go-containerregistry v0.8.1-0.20220216220642-00c59d91847c github.com/onsi/gomega v1.19.0 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 - github.com/schollz/progressbar/v3 v3.8.6 + github.com/schollz/progressbar/v3 v3.9.0 github.com/shipwright-io/build v0.9.0 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 47a2f57fa..ae7a8eafa 100644 --- a/go.sum +++ b/go.sum @@ -1254,8 +1254,8 @@ github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYI github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig= github.com/sanposhiho/wastedassign/v2 v2.0.6/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/schollz/progressbar/v3 v3.8.6 h1:QruMUdzZ1TbEP++S1m73OqRJk20ON11m6Wqv4EoGg8c= -github.com/schollz/progressbar/v3 v3.8.6/go.mod h1:W5IEwbJecncFGBvuEh4A7HT1nZZ6WNIL2i3qbnI0WKY= +github.com/schollz/progressbar/v3 v3.9.0 h1:k9SRNQ8KZyibz1UZOaKxnkUE3iGtmGSDt1YY9KlCYQk= +github.com/schollz/progressbar/v3 v3.9.0/go.mod h1:W5IEwbJecncFGBvuEh4A7HT1nZZ6WNIL2i3qbnI0WKY= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= github.com/securego/gosec/v2 v2.9.1/go.mod h1:oDcDLcatOJxkCGaCaq8lua1jTnYf6Sou4wdiJ1n4iHc= diff --git a/vendor/github.com/schollz/progressbar/v3/progressbar.go b/vendor/github.com/schollz/progressbar/v3/progressbar.go index 7720bd89a..487aac271 100644 --- a/vendor/github.com/schollz/progressbar/v3/progressbar.go +++ b/vendor/github.com/schollz/progressbar/v3/progressbar.go @@ -76,6 +76,10 @@ type config struct { showIterationsPerSecond bool showIterationsCount bool + // whether the progress bar should show elapsed time. + // always enabled if predictTime is true. + elapsedTime bool + // whether the progress bar should attempt to predict the finishing // time of the progress based on the start time and the average // number of seconds between increments. @@ -179,6 +183,13 @@ func OptionEnableColorCodes(colorCodes bool) Option { } } +// OptionSetElapsedTime will enable elapsed time. always enabled if OptionSetPredictTime is true. +func OptionSetElapsedTime(elapsedTime bool) Option { + return func(p *ProgressBar) { + p.config.elapsedTime = elapsedTime + } +} + // OptionSetPredictTime will also attempt to predict the time remaining. func OptionSetPredictTime(predictTime bool) Option { return func(p *ProgressBar) { @@ -264,6 +275,7 @@ func NewOptions64(max int64, options ...Option) *ProgressBar { width: 40, max: max, throttleDuration: 0 * time.Nanosecond, + elapsedTime: true, predictTime: true, spinnerType: 9, invisible: false, @@ -317,7 +329,7 @@ func DefaultBytes(maxBytes int64, description ...string) *ProgressBar { if len(description) > 0 { desc = description[0] } - bar := NewOptions64( + return NewOptions64( maxBytes, OptionSetDescription(desc), OptionSetWriter(os.Stderr), @@ -326,13 +338,12 @@ func DefaultBytes(maxBytes int64, description ...string) *ProgressBar { OptionThrottle(65*time.Millisecond), OptionShowCount(), OptionOnCompletion(func() { - fmt.Printf("\n") + fmt.Fprint(os.Stderr, "\n") }), OptionSpinnerType(14), OptionFullWidth(), + OptionSetRenderBlankState(true), ) - bar.RenderBlank() - return bar } // DefaultBytesSilent is the same as DefaultBytes, but does not output anywhere. @@ -344,7 +355,7 @@ func DefaultBytesSilent(maxBytes int64, description ...string) *ProgressBar { if len(description) > 0 { desc = description[0] } - bar := NewOptions64( + return NewOptions64( maxBytes, OptionSetDescription(desc), OptionSetWriter(ioutil.Discard), @@ -355,8 +366,6 @@ func DefaultBytesSilent(maxBytes int64, description ...string) *ProgressBar { OptionSpinnerType(14), OptionFullWidth(), ) - bar.RenderBlank() - return bar } // Default provides a progressbar with recommended defaults. @@ -366,7 +375,7 @@ func Default(max int64, description ...string) *ProgressBar { if len(description) > 0 { desc = description[0] } - bar := NewOptions64( + return NewOptions64( max, OptionSetDescription(desc), OptionSetWriter(os.Stderr), @@ -375,13 +384,12 @@ func Default(max int64, description ...string) *ProgressBar { OptionShowCount(), OptionShowIts(), OptionOnCompletion(func() { - fmt.Printf("\n") + fmt.Fprint(os.Stderr, "\n") }), OptionSpinnerType(14), OptionFullWidth(), + OptionSetRenderBlankState(true), ) - bar.RenderBlank() - return bar } // DefaultSilent is the same as Default, but does not output anywhere. @@ -393,7 +401,7 @@ func DefaultSilent(max int64, description ...string) *ProgressBar { if len(description) > 0 { desc = description[0] } - bar := NewOptions64( + return NewOptions64( max, OptionSetDescription(desc), OptionSetWriter(ioutil.Discard), @@ -404,8 +412,6 @@ func DefaultSilent(max int64, description ...string) *ProgressBar { OptionSpinnerType(14), OptionFullWidth(), ) - bar.RenderBlank() - return bar } // String returns the current rendered version of the progress bar. @@ -419,6 +425,9 @@ func (p *ProgressBar) RenderBlank() error { if p.config.invisible { return nil } + if p.state.currentNum == 0 { + p.state.lastShown = time.Time{} + } return p.render() } @@ -517,7 +526,10 @@ func (p *ProgressBar) Clear() error { // can be changed on the fly (as for a slow running process). func (p *ProgressBar) Describe(description string) { p.config.description = description - p.RenderBlank() + if p.config.invisible { + return + } + p.render() } // New64 returns a new ProgressBar @@ -557,7 +569,7 @@ func (p *ProgressBar) ChangeMax64(newMax int64) { p.Add(0) // re-render } -// IsFinished returns true if progreess bar is completed +// IsFinished returns true if progress bar is completed func (p *ProgressBar) IsFinished() bool { return p.state.finished } @@ -671,7 +683,11 @@ func renderProgressBar(c config, s *state) (int, error) { if len(s.counterLastTenRates) == 0 || s.finished { // if no average samples, or if finished, // then average rate should be the total rate - averageRate = s.currentBytes / time.Since(s.startTime).Seconds() + if t := time.Since(s.startTime).Seconds(); t > 0 { + averageRate = s.currentBytes / t + } else { + averageRate = 0 + } } // show iteration count in "current/total" iterations format @@ -702,19 +718,15 @@ func renderProgressBar(c config, s *state) (int, error) { } } - // show rolling average rate in kB/sec or MB/sec - if c.showBytes { + // show rolling average rate + if c.showBytes && averageRate > 0 && !math.IsInf(averageRate, 1) { if bytesString == "" { bytesString += "(" } else { bytesString += ", " } - kbPerSecond := averageRate / 1024.0 - if kbPerSecond > 1024.0 { - bytesString += fmt.Sprintf("%0.3f MB/s", kbPerSecond/1024.0) - } else if kbPerSecond > 0 { - bytesString += fmt.Sprintf("%0.3f kB/s", kbPerSecond) - } + currentHumanize, currentSuffix := humanizeBytes(averageRate) + bytesString += fmt.Sprintf("%s%s/s", currentHumanize, currentSuffix) } // show iterations rate @@ -735,13 +747,16 @@ func renderProgressBar(c config, s *state) (int, error) { } // show time prediction in "current/total" seconds format - if c.predictTime { - leftBrac = (time.Duration(time.Since(s.startTime).Seconds()) * time.Second).String() + switch { + case c.predictTime: rightBracNum := (time.Duration((1/averageRate)*(float64(c.max)-float64(s.currentNum))) * time.Second) if rightBracNum.Seconds() < 0 { rightBracNum = 0 * time.Second } rightBrac = rightBracNum.String() + fallthrough + case c.elapsedTime: + leftBrac = (time.Duration(time.Since(s.startTime).Seconds()) * time.Second).String() } if c.fullWidth && !c.ignoreLength { @@ -787,12 +802,21 @@ func renderProgressBar(c config, s *state) (int, error) { repeatAmount = 0 } if c.ignoreLength { - str = fmt.Sprintf("\r%s %s %s ", - spinners[c.spinnerType][int(math.Round(math.Mod(float64(time.Since(s.startTime).Milliseconds()/100), float64(len(spinners[c.spinnerType])))))], - c.description, - bytesString, - ) - } else if leftBrac == "" { + if c.elapsedTime { + str = fmt.Sprintf("\r%s %s %s [%s] ", + spinners[c.spinnerType][int(math.Round(math.Mod(float64(time.Since(s.startTime).Milliseconds()/100), float64(len(spinners[c.spinnerType])))))], + c.description, + bytesString, + leftBrac, + ) + } else { + str = fmt.Sprintf("\r%s %s %s ", + spinners[c.spinnerType][int(math.Round(math.Mod(float64(time.Since(s.startTime).Milliseconds()/100), float64(len(spinners[c.spinnerType])))))], + c.description, + bytesString, + ) + } + } else if rightBrac == "" { str = fmt.Sprintf("\r%s%4d%% %s%s%s%s %s ", c.description, s.currentPercent, @@ -839,6 +863,9 @@ func renderProgressBar(c config, s *state) (int, error) { } func clearProgressBar(c config, s state) error { + if s.maxLineWidth == 0 { + return nil + } if c.useANSICodes { // write the "clear current line" ANSI escape sequence return writeString(c, "\033[2K\r") @@ -846,7 +873,7 @@ func clearProgressBar(c config, s state) error { // fill the empty content // to overwrite the progress bar and jump // back to the beginning of the line - str := fmt.Sprintf("\r%s\r", strings.Repeat(" ", s.maxLineWidth)) + str := fmt.Sprintf("\r%s", strings.Repeat(" ", s.maxLineWidth)) return writeString(c, str) // the following does not show correctly if the previous line is longer than subsequent line // return writeString(c, "\r") @@ -928,7 +955,7 @@ func humanizeBytes(s float64) (string, string) { sizes := []string{" B", " kB", " MB", " GB", " TB", " PB", " EB"} base := 1024.0 if s < 10 { - return fmt.Sprintf("%2.0f", s), "B" + return fmt.Sprintf("%2.0f", s), sizes[0] } e := math.Floor(logn(float64(s), base)) suffix := sizes[int(e)] diff --git a/vendor/modules.txt b/vendor/modules.txt index 229627448..7300c2b2b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -359,7 +359,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.8.6 +# github.com/schollz/progressbar/v3 v3.9.0 ## explicit; go 1.13 github.com/schollz/progressbar/v3 # github.com/shipwright-io/build v0.9.0