@@ -188,7 +188,7 @@ func OptionEnableColorCodes(colorCodes bool) Option {
188188 }
189189}
190190
191- // OptionSetElapsedTime will enable elapsed time. always enabled if OptionSetPredictTime is true.
191+ // OptionSetElapsedTime will enable elapsed time. Always enabled if OptionSetPredictTime is true.
192192func OptionSetElapsedTime (elapsedTime bool ) Option {
193193 return func (p * ProgressBar ) {
194194 p .config .elapsedTime = elapsedTime
@@ -484,12 +484,12 @@ func (p *ProgressBar) Add(num int) error {
484484 return p .Add64 (int64 (num ))
485485}
486486
487- // Set wil set the bar to a current number
487+ // Set will set the bar to a current number
488488func (p * ProgressBar ) Set (num int ) error {
489489 return p .Set64 (int64 (num ))
490490}
491491
492- // Set64 wil set the bar to a current number
492+ // Set64 will set the bar to a current number
493493func (p * ProgressBar ) Set64 (num int64 ) error {
494494 p .lock .Lock ()
495495 toAdd := num - int64 (p .state .currentBytes )
@@ -795,12 +795,9 @@ func renderProgressBar(c config, s *state) (int, error) {
795795 }
796796
797797 if c .fullWidth && ! c .ignoreLength {
798- width , _ , err := term . GetSize ( int ( os . Stdout . Fd ()) )
798+ width , err := termWidth ( )
799799 if err != nil {
800- width , _ , err = term .GetSize (int (os .Stderr .Fd ()))
801- if err != nil {
802- width = 80
803- }
800+ width = 80
804801 }
805802
806803 amend := 1 // an extra space at eol
@@ -1062,3 +1059,17 @@ func humanizeBytes(s float64) (string, string) {
10621059func logn (n , b float64 ) float64 {
10631060 return math .Log (n ) / math .Log (b )
10641061}
1062+
1063+ // termWidth function returns the visible width of the current terminal
1064+ // and can be redefined for testing
1065+ var termWidth = func () (width int , err error ) {
1066+ width , _ , err = term .GetSize (int (os .Stdout .Fd ()))
1067+ if err == nil {
1068+ return width , nil
1069+ }
1070+ width , _ , err = term .GetSize (int (os .Stderr .Fd ()))
1071+ if err == nil {
1072+ return width , nil
1073+ }
1074+ return 0 , err
1075+ }
0 commit comments