@@ -46,7 +46,7 @@ def create_wrapper(wrapper):
4646 >>> print(create_wrapper(('a', 'b')))
4747 a{}b
4848 '''
49- if isinstance (wrapper , tuple ) and len (wrapper ) == 2 :
49+ if isinstance (wrapper , tuple ) and utils . len_color (wrapper ) == 2 :
5050 a , b = wrapper
5151 wrapper = (a or '' ) + '{}' + (b or '' )
5252 elif not wrapper :
@@ -392,7 +392,7 @@ def __call__(
392392 sample_times .pop (0 )
393393 sample_values .pop (0 )
394394 else :
395- if len (sample_times ) > self .samples :
395+ if progress . custom_len (sample_times ) > self .samples :
396396 sample_times .pop (0 )
397397 sample_values .pop (0 )
398398
@@ -673,6 +673,7 @@ class AnimatedMarker(TimeSensitiveWidgetBase):
673673 '''An animated marker for the progress bar which defaults to appear as if
674674 it were rotating.
675675 '''
676+
676677 def __init__ (
677678 self ,
678679 markers = '|/-\\ ' ,
@@ -696,7 +697,7 @@ def __call__(self, progress: ProgressBarMixinBase, data: Data, width=None):
696697 if progress .end_time :
697698 return self .default
698699
699- marker = self .markers [data ['updates' ] % len (self .markers )]
700+ marker = self .markers [data ['updates' ] % utils . len_color (self .markers )]
700701 if self .marker_wrap :
701702 marker = self .marker_wrap .format (marker )
702703
@@ -745,6 +746,9 @@ class Percentage(FormatWidgetMixin, WidgetBase):
745746 bg_na : terminal .Color | None = colors .black
746747 bg_value : terminal .OptionalColor | None = None
747748
749+ def _uses_colors (self ):
750+ return self .fg_na or self .fg_value or self .bg_na or self .bg_value
751+
748752 def __init__ (self , format = '%(percentage)3d%%' , na = 'N/A%%' , ** kwargs ):
749753 self .na = na
750754 FormatWidgetMixin .__init__ (self , format = format , ** kwargs )
@@ -757,14 +761,12 @@ def get_format(
757761 percentage = data .get ('percentage' , base .Undefined )
758762 if not percentage and percentage != 0 :
759763 output = self .na
760- value = None
761764 else :
762- value = percentage / 100
763765 output = FormatWidgetMixin .get_format (self , progress , data , format )
764766
765767 return terminal .apply_colors (
766768 output ,
767- value ,
769+ data . get ( 'percentage' ) ,
768770 fg = self .fg_value ,
769771 bg = self .bg_value ,
770772 fg_none = self .fg_na ,
@@ -798,10 +800,8 @@ def __call__(
798800 # If max_value is not available, display N/A
799801 if data .get ('max_value' ):
800802 data ['max_value_s' ] = data ['max_value' ]
801- value = data .get ('value' , 0 ) / data ['max_value' ]
802803 else :
803804 data ['max_value_s' ] = 'N/A'
804- value = None
805805
806806 # if value is not available it's the zeroth iteration
807807 if data .get ('value' ):
@@ -841,7 +841,7 @@ def __call__(
841841
842842 return terminal .apply_colors (
843843 formatted ,
844- value ,
844+ data . get ( 'percentage' ) ,
845845 fg = self .fg_value ,
846846 bg = self .bg_value ,
847847 fg_none = self .fg_na ,
@@ -898,25 +898,28 @@ def __call__(
898898 fill = converters .to_unicode (self .fill (progress , data , width ))
899899
900900 # Make sure we ignore invisible characters when filling
901- width += len (marker ) - progress .custom_len (marker )
902-
903- if marker and width > 0 :
904- value = len (marker ) / width
905- else :
906- value = 0
901+ width += utils .len_color (marker ) - progress .custom_len (marker )
907902
908903 if self .fill_left :
909904 marker = marker .ljust (width , fill )
910905 else :
911906 marker = marker .rjust (width , fill )
912907
913- marker = terminal .apply_colors (
914- marker ,
915- value ,
908+ marker = self .apply_colors (progress , data , marker )
909+ return left + marker + right
910+
911+ def apply_colors (
912+ self ,
913+ progress : ProgressBarMixinBase ,
914+ data : Data , output : str
915+ ):
916+ output = terminal .apply_colors (
917+ output ,
918+ percentage = data .get ('percentage' ),
916919 fg = self .fg_value ,
917920 bg = self .bg_value ,
918921 )
919- return left + marker + right
922+ return output
920923
921924
922925class ReverseBar (Bar ):
@@ -1023,7 +1026,7 @@ class VariableMixin:
10231026 def __init__ (self , name , ** kwargs ):
10241027 if not isinstance (name , str ):
10251028 raise TypeError ('Variable(): argument must be a string' )
1026- if len (name .split ()) > 1 :
1029+ if utils . len_color (name .split ()) > 1 :
10271030 raise ValueError ('Variable(): argument must be single word' )
10281031 self .name = name
10291032
@@ -1103,7 +1106,7 @@ def __init__(
11031106 )
11041107
11051108 def get_values (self , progress : ProgressBarMixinBase , data : Data ):
1106- ranges = [0.0 ] * len (self .markers )
1109+ ranges = [0.0 ] * progress . custom_len (self .markers )
11071110 for value in data ['variables' ][self .name ] or []:
11081111 if not isinstance (value , (int , float )):
11091112 # Progress is (value, max)
@@ -1116,7 +1119,7 @@ def get_values(self, progress: ProgressBarMixinBase, data: Data):
11161119 % value
11171120 )
11181121
1119- range_ = value * (len (ranges ) - 1 )
1122+ range_ = value * (progress . custom_len (ranges ) - 1 )
11201123 pos = int (range_ )
11211124 frac = range_ % 1
11221125 ranges [pos ] += 1 - frac
@@ -1200,14 +1203,16 @@ def __call__(
12001203
12011204 marker = self .markers [- 1 ] * int (num_chars )
12021205
1203- marker_idx = int ((num_chars % 1 ) * (len (self .markers ) - 1 ))
1206+ marker_idx = int (
1207+ (num_chars % 1 ) * (progress .custom_len (self .markers ) - 1 )
1208+ )
12041209 if marker_idx :
12051210 marker += self .markers [marker_idx ]
12061211
12071212 marker = converters .to_unicode (marker )
12081213
12091214 # Make sure we ignore invisible characters when filling
1210- width += len (marker ) - progress .custom_len (marker )
1215+ width += progress . custom_len (marker ) - progress .custom_len (marker )
12111216 marker = marker .ljust (width , self .markers [0 ])
12121217
12131218 return left + marker + right
@@ -1234,7 +1239,12 @@ def __call__( # type: ignore
12341239 center_len = progress .custom_len (center )
12351240 center_left = int ((width - center_len ) / 2 )
12361241 center_right = center_left + center_len
1237- return bar [:center_left ] + center + bar [center_right :]
1242+
1243+ return bar [:center_left ] + center + self .apply_colors (
1244+ progress ,
1245+ data ,
1246+ bar [center_right :]
1247+ )
12381248
12391249
12401250class PercentageLabelBar (Percentage , FormatLabelBar ):
0 commit comments