Skip to content

Commit

Permalink
bug fix: make sure repeat is not negative
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed May 4, 2020
1 parent b9d36bb commit a6c371e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ func renderProgressBar(c config, s state) (int, error) {
Progress Bar format
Description % |------ | (kb/s) (iteration count) (iteration rate) (predict time)
*/
repeatAmount := c.width - s.currentSaucerSize
if repeatAmount < 0 {
repeatAmount = 0
}
if c.ignoreLength {
str = fmt.Sprintf("\r%s %s %s ",
spinners[c.spinnerType][int(math.Round(math.Mod(float64(time.Since(s.counterTime).Milliseconds()/100), float64(len(spinners[c.spinnerType])))))],
Expand All @@ -621,7 +625,7 @@ func renderProgressBar(c config, s state) (int, error) {
s.currentPercent,
c.theme.BarStart,
saucer,
strings.Repeat(c.theme.SaucerPadding, c.width-s.currentSaucerSize),
strings.Repeat(c.theme.SaucerPadding, repeatAmount),
c.theme.BarEnd,
bytesString,
)
Expand All @@ -631,7 +635,7 @@ func renderProgressBar(c config, s state) (int, error) {
s.currentPercent,
c.theme.BarStart,
saucer,
strings.Repeat(c.theme.SaucerPadding, c.width-s.currentSaucerSize),
strings.Repeat(c.theme.SaucerPadding, repeatAmount),
c.theme.BarEnd,
bytesString,
leftBrac,
Expand Down

0 comments on commit a6c371e

Please sign in to comment.