Skip to content

Commit d773ff3

Browse files
authored
Merge pull request #193 from luo-cheng-xi/fix-change-max
fix:fixed the bug that changMax isn't working.
2 parents 191b8ab + 77ac51e commit d773ff3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

progressbar.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,7 @@ func NewOptions64(max int64, options ...Option) *ProgressBar {
364364

365365
// ignoreLength if max bytes not known
366366
if b.config.max == -1 {
367-
b.config.ignoreLength = true
368-
b.config.max = int64(b.config.width)
369-
b.config.predictTime = false
367+
b.lengthUnknown()
370368
}
371369

372370
b.config.maxHumanized, b.config.maxHumanizedSuffix = humanizeBytes(float64(b.config.max),
@@ -759,6 +757,7 @@ func (p *ProgressBar) ChangeMax64(newMax int64) {
759757
p.config.useIECUnits)
760758
}
761759

760+
p.lengthKnown(newMax)
762761
p.lock.Unlock() // so p.Add can lock
763762

764763
p.Add(0) // re-render
@@ -841,6 +840,20 @@ func (p *ProgressBar) render() error {
841840
return nil
842841
}
843842

843+
// lengthUnknown sets the progress bar to ignore the length
844+
func (p *ProgressBar) lengthUnknown() {
845+
p.config.ignoreLength = true
846+
p.config.max = int64(p.config.width)
847+
p.config.predictTime = false
848+
}
849+
850+
// lengthKnown sets the progress bar to do not ignore the length
851+
func (p *ProgressBar) lengthKnown(max int64) {
852+
p.config.ignoreLength = false
853+
p.config.max = max
854+
p.config.predictTime = true
855+
}
856+
844857
// State returns the current state
845858
func (p *ProgressBar) State() State {
846859
p.lock.Lock()

0 commit comments

Comments
 (0)