Skip to content

Commit

Permalink
fix:fixed the bug that changMax isn't working.
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxilo committed Aug 28, 2024
1 parent 03fc4e9 commit 77ac51e
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 @@ -343,9 +343,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 @@ -656,6 +654,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 @@ -726,6 +725,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 77ac51e

Please sign in to comment.