From 77ac51e8e820ef0a391932f89f0919ec68b457fb Mon Sep 17 00:00:00 2001 From: luo-cheng-xi Date: Tue, 27 Aug 2024 23:30:00 -0400 Subject: [PATCH] fix:fixed the bug that changMax isn't working. --- progressbar.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/progressbar.go b/progressbar.go index 56c147e..089b8b7 100644 --- a/progressbar.go +++ b/progressbar.go @@ -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), @@ -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 @@ -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()