@@ -756,14 +756,14 @@ def _format(val, valtype, floatfmt, missingval="", has_invisible=True):
756
756
return "{0}" .format (val )
757
757
758
758
759
- def _align_header (header , alignment , width , visible_width , is_multiline = False ):
759
+ def _align_header (header , alignment , width , visible_width , is_multiline = False , width_fn = None ):
760
760
"Pad string header to width chars given known visible_width of the header."
761
761
if is_multiline :
762
762
header_lines = re .split (_multiline_codes , header )
763
- padded_lines = [_align_header (h , alignment , width , visible_width ) for h in header_lines ]
763
+ padded_lines = [_align_header (h , alignment , width , width_fn ( h ) ) for h in header_lines ]
764
764
return "\n " .join (padded_lines )
765
765
# else: not multiline
766
- ninvisible = max ( 0 , len (header ) - visible_width )
766
+ ninvisible = len (header ) - visible_width
767
767
width += ninvisible
768
768
if alignment == "left" :
769
769
return _padright (width , header )
@@ -1296,7 +1296,7 @@ def tabulate(tabular_data, headers=(), tablefmt="simple",
1296
1296
t_cols = cols or [['' ]] * len (headers )
1297
1297
t_aligns = aligns or [stralign ] * len (headers )
1298
1298
minwidths = [max (minw , max (width_fn (cl ) for cl in c )) for minw , c in zip (minwidths , t_cols )]
1299
- headers = [_align_header (h , a , minw , width_fn (h ), is_multiline )
1299
+ headers = [_align_header (h , a , minw , width_fn (h ), is_multiline , width_fn )
1300
1300
for h , a , minw in zip (headers , t_aligns , minwidths )]
1301
1301
rows = list (zip (* cols ))
1302
1302
else :
0 commit comments