Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:fixed the bug that changMax isn't working. #193

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading