Skip to content

Commit

Permalink
Merge pull request #193 from luo-cheng-xi/fix-change-max
Browse files Browse the repository at this point in the history
fix:fixed the bug that changMax isn't working.
  • Loading branch information
schollz authored Sep 15, 2024
2 parents 191b8ab + 77ac51e commit d773ff3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ func NewOptions64(max int64, options ...Option) *ProgressBar {

// ignoreLength if max bytes not known
if b.config.max == -1 {
b.config.ignoreLength = true
b.config.max = int64(b.config.width)
b.config.predictTime = false
b.lengthUnknown()
}

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

p.lengthKnown(newMax)
p.lock.Unlock() // so p.Add can lock

p.Add(0) // re-render
Expand Down Expand Up @@ -841,6 +840,20 @@ func (p *ProgressBar) render() error {
return nil
}

// lengthUnknown sets the progress bar to ignore the length
func (p *ProgressBar) lengthUnknown() {
p.config.ignoreLength = true
p.config.max = int64(p.config.width)
p.config.predictTime = false
}

// lengthKnown sets the progress bar to do not ignore the length
func (p *ProgressBar) lengthKnown(max int64) {
p.config.ignoreLength = false
p.config.max = max
p.config.predictTime = true
}

// State returns the current state
func (p *ProgressBar) State() State {
p.lock.Lock()
Expand Down

0 comments on commit d773ff3

Please sign in to comment.