@@ -83,6 +83,9 @@ type config struct {
83
83
showIterationsPerSecond bool
84
84
showIterationsCount bool
85
85
86
+ // whether the progress bar should show the total bytes (e.g. 23/24 or 23/-, vs. just 23).
87
+ showTotalBytes bool
88
+
86
89
// whether the progress bar should show elapsed time.
87
90
// always enabled if predictTime is true.
88
91
elapsedTime bool
@@ -309,6 +312,13 @@ func OptionShowElapsedTimeOnFinish() Option {
309
312
}
310
313
}
311
314
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
+
312
322
// OptionSetItsString sets what's displayed for iterations a second. The default is "it" which would display: "it/s"
313
323
func OptionSetItsString (iterationString string ) Option {
314
324
return func (p * ProgressBar ) {
@@ -403,6 +413,7 @@ func NewOptions64(max int64, options ...Option) *ProgressBar {
403
413
spinnerType : 9 ,
404
414
invisible : false ,
405
415
spinnerChangeInterval : 100 * time .Millisecond ,
416
+ showTotalBytes : true ,
406
417
},
407
418
}
408
419
@@ -482,6 +493,7 @@ func DefaultBytes(maxBytes int64, description ...string) *ProgressBar {
482
493
OptionSetDescription (desc ),
483
494
OptionSetWriter (os .Stderr ),
484
495
OptionShowBytes (true ),
496
+ OptionShowTotalBytes (true ),
485
497
OptionSetWidth (10 ),
486
498
OptionThrottle (65 * time .Millisecond ),
487
499
OptionShowCount (),
@@ -508,6 +520,7 @@ func DefaultBytesSilent(maxBytes int64, description ...string) *ProgressBar {
508
520
OptionSetDescription (desc ),
509
521
OptionSetWriter (io .Discard ),
510
522
OptionShowBytes (true ),
523
+ OptionShowTotalBytes (true ),
511
524
OptionSetWidth (10 ),
512
525
OptionThrottle (65 * time .Millisecond ),
513
526
OptionShowCount (),
@@ -528,6 +541,7 @@ func Default(max int64, description ...string) *ProgressBar {
528
541
OptionSetDescription (desc ),
529
542
OptionSetWriter (os .Stderr ),
530
543
OptionSetWidth (10 ),
544
+ OptionShowTotalBytes (true ),
531
545
OptionThrottle (65 * time .Millisecond ),
532
546
OptionShowCount (),
533
547
OptionShowIts (),
@@ -554,6 +568,7 @@ func DefaultSilent(max int64, description ...string) *ProgressBar {
554
568
OptionSetDescription (desc ),
555
569
OptionSetWriter (io .Discard ),
556
570
OptionSetWidth (10 ),
571
+ OptionShowTotalBytes (true ),
557
572
OptionThrottle (65 * time .Millisecond ),
558
573
OptionShowCount (),
559
574
OptionShowIts (),
@@ -1010,21 +1025,32 @@ func renderProgressBar(c config, s *state) (int, error) {
1010
1025
if c .showBytes {
1011
1026
currentHumanize , currentSuffix := humanizeBytes (s .currentBytes , c .useIECUnits )
1012
1027
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 {
1016
1036
sb .WriteString (fmt .Sprintf ("%s%s/%s%s" ,
1017
1037
currentHumanize , currentSuffix , c .maxHumanized , c .maxHumanizedSuffix ))
1038
+ } else {
1039
+ sb .WriteString (fmt .Sprintf ("%s%s" , currentHumanize , currentSuffix ))
1018
1040
}
1019
- } else {
1041
+ } else if c . showTotalBytes {
1020
1042
sb .WriteString (fmt .Sprintf ("%.0f/%d" , s .currentBytes , c .max ))
1043
+ } else {
1044
+ sb .WriteString (fmt .Sprintf ("%.0f" , s .currentBytes ))
1021
1045
}
1022
1046
} else {
1023
1047
if c .showBytes {
1024
1048
currentHumanize , currentSuffix := humanizeBytes (s .currentBytes , c .useIECUnits )
1025
1049
sb .WriteString (fmt .Sprintf ("%s%s" , currentHumanize , currentSuffix ))
1026
- } else {
1050
+ } else if c . showTotalBytes {
1027
1051
sb .WriteString (fmt .Sprintf ("%.0f/%s" , s .currentBytes , "-" ))
1052
+ } else {
1053
+ sb .WriteString (fmt .Sprintf ("%.0f" , s .currentBytes ))
1028
1054
}
1029
1055
}
1030
1056
}
0 commit comments