File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff 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
845858func (p * ProgressBar ) State () State {
846859 p .lock .Lock ()
You can’t perform that action at this time.
0 commit comments