WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a6c371e

Browse files
committed
bug fix: make sure repeat is not negative
1 parent b9d36bb commit a6c371e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

progressbar.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ func renderProgressBar(c config, s state) (int, error) {
609609
Progress Bar format
610610
Description % |------ | (kb/s) (iteration count) (iteration rate) (predict time)
611611
*/
612+
repeatAmount := c.width - s.currentSaucerSize
613+
if repeatAmount < 0 {
614+
repeatAmount = 0
615+
}
612616
if c.ignoreLength {
613617
str = fmt.Sprintf("\r%s %s %s ",
614618
spinners[c.spinnerType][int(math.Round(math.Mod(float64(time.Since(s.counterTime).Milliseconds()/100), float64(len(spinners[c.spinnerType])))))],
@@ -621,7 +625,7 @@ func renderProgressBar(c config, s state) (int, error) {
621625
s.currentPercent,
622626
c.theme.BarStart,
623627
saucer,
624-
strings.Repeat(c.theme.SaucerPadding, c.width-s.currentSaucerSize),
628+
strings.Repeat(c.theme.SaucerPadding, repeatAmount),
625629
c.theme.BarEnd,
626630
bytesString,
627631
)
@@ -631,7 +635,7 @@ func renderProgressBar(c config, s state) (int, error) {
631635
s.currentPercent,
632636
c.theme.BarStart,
633637
saucer,
634-
strings.Repeat(c.theme.SaucerPadding, c.width-s.currentSaucerSize),
638+
strings.Repeat(c.theme.SaucerPadding, repeatAmount),
635639
c.theme.BarEnd,
636640
bytesString,
637641
leftBrac,

0 commit comments

Comments
 (0)