@@ -83,6 +83,9 @@ type config struct {
8383 showIterationsPerSecond bool
8484 showIterationsCount bool
8585
86+ // whether the progress bar should show the total bytes (e.g. 23/24 or 23/-, vs. just 23).
87+ showTotalBytes bool
88+
8689 // whether the progress bar should show elapsed time.
8790 // always enabled if predictTime is true.
8891 elapsedTime bool
@@ -309,6 +312,13 @@ func OptionShowElapsedTimeOnFinish() Option {
309312 }
310313}
311314
315+ // OptionShowTotalBytes will keep the display of total bytes.
316+ func OptionShowTotalBytes (flag bool ) Option {
317+ return func (p * ProgressBar ) {
318+ p .config .showTotalBytes = flag
319+ }
320+ }
321+
312322// OptionSetItsString sets what's displayed for iterations a second. The default is "it" which would display: "it/s"
313323func OptionSetItsString (iterationString string ) Option {
314324 return func (p * ProgressBar ) {
@@ -403,6 +413,7 @@ func NewOptions64(max int64, options ...Option) *ProgressBar {
403413 spinnerType : 9 ,
404414 invisible : false ,
405415 spinnerChangeInterval : 100 * time .Millisecond ,
416+ showTotalBytes : true ,
406417 },
407418 }
408419
@@ -482,6 +493,7 @@ func DefaultBytes(maxBytes int64, description ...string) *ProgressBar {
482493 OptionSetDescription (desc ),
483494 OptionSetWriter (os .Stderr ),
484495 OptionShowBytes (true ),
496+ OptionShowTotalBytes (true ),
485497 OptionSetWidth (10 ),
486498 OptionThrottle (65 * time .Millisecond ),
487499 OptionShowCount (),
@@ -508,6 +520,7 @@ func DefaultBytesSilent(maxBytes int64, description ...string) *ProgressBar {
508520 OptionSetDescription (desc ),
509521 OptionSetWriter (io .Discard ),
510522 OptionShowBytes (true ),
523+ OptionShowTotalBytes (true ),
511524 OptionSetWidth (10 ),
512525 OptionThrottle (65 * time .Millisecond ),
513526 OptionShowCount (),
@@ -528,6 +541,7 @@ func Default(max int64, description ...string) *ProgressBar {
528541 OptionSetDescription (desc ),
529542 OptionSetWriter (os .Stderr ),
530543 OptionSetWidth (10 ),
544+ OptionShowTotalBytes (true ),
531545 OptionThrottle (65 * time .Millisecond ),
532546 OptionShowCount (),
533547 OptionShowIts (),
@@ -554,6 +568,7 @@ func DefaultSilent(max int64, description ...string) *ProgressBar {
554568 OptionSetDescription (desc ),
555569 OptionSetWriter (io .Discard ),
556570 OptionSetWidth (10 ),
571+ OptionShowTotalBytes (true ),
557572 OptionThrottle (65 * time .Millisecond ),
558573 OptionShowCount (),
559574 OptionShowIts (),
@@ -1010,21 +1025,32 @@ func renderProgressBar(c config, s *state) (int, error) {
10101025 if c .showBytes {
10111026 currentHumanize , currentSuffix := humanizeBytes (s .currentBytes , c .useIECUnits )
10121027 if currentSuffix == c .maxHumanizedSuffix {
1013- sb .WriteString (fmt .Sprintf ("%s/%s%s" ,
1014- currentHumanize , c .maxHumanized , c .maxHumanizedSuffix ))
1015- } else {
1028+ if c .showTotalBytes {
1029+ sb .WriteString (fmt .Sprintf ("%s/%s%s" ,
1030+ currentHumanize , c .maxHumanized , c .maxHumanizedSuffix ))
1031+ } else {
1032+ sb .WriteString (fmt .Sprintf ("%s%s" ,
1033+ currentHumanize , c .maxHumanizedSuffix ))
1034+ }
1035+ } else if c .showTotalBytes {
10161036 sb .WriteString (fmt .Sprintf ("%s%s/%s%s" ,
10171037 currentHumanize , currentSuffix , c .maxHumanized , c .maxHumanizedSuffix ))
1038+ } else {
1039+ sb .WriteString (fmt .Sprintf ("%s%s" , currentHumanize , currentSuffix ))
10181040 }
1019- } else {
1041+ } else if c . showTotalBytes {
10201042 sb .WriteString (fmt .Sprintf ("%.0f/%d" , s .currentBytes , c .max ))
1043+ } else {
1044+ sb .WriteString (fmt .Sprintf ("%.0f" , s .currentBytes ))
10211045 }
10221046 } else {
10231047 if c .showBytes {
10241048 currentHumanize , currentSuffix := humanizeBytes (s .currentBytes , c .useIECUnits )
10251049 sb .WriteString (fmt .Sprintf ("%s%s" , currentHumanize , currentSuffix ))
1026- } else {
1050+ } else if c . showTotalBytes {
10271051 sb .WriteString (fmt .Sprintf ("%.0f/%s" , s .currentBytes , "-" ))
1052+ } else {
1053+ sb .WriteString (fmt .Sprintf ("%.0f" , s .currentBytes ))
10281054 }
10291055 }
10301056 }
0 commit comments