Skip to content

Commit 2e9592c

Browse files
meeuwastanin
authored andcommitted
Merged in meeuw/python-tabulate/fixheaders (pull request astanin#44)
Fix the width of headers with wide characters (could be broken)
2 parents eee620e + 6e7cc57 commit 2e9592c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tabulate.py

100644100755
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,14 @@ def _format(val, valtype, floatfmt, missingval="", has_invisible=True):
756756
return "{0}".format(val)
757757

758758

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):
760760
"Pad string header to width chars given known visible_width of the header."
761761
if is_multiline:
762762
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]
764764
return "\n".join(padded_lines)
765765
# else: not multiline
766-
ninvisible = max(0, len(header) - visible_width)
766+
ninvisible = len(header) - visible_width
767767
width += ninvisible
768768
if alignment == "left":
769769
return _padright(width, header)
@@ -1296,7 +1296,7 @@ def tabulate(tabular_data, headers=(), tablefmt="simple",
12961296
t_cols = cols or [['']] * len(headers)
12971297
t_aligns = aligns or [stralign] * len(headers)
12981298
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)
13001300
for h, a, minw in zip(headers, t_aligns, minwidths)]
13011301
rows = list(zip(*cols))
13021302
else:

0 commit comments

Comments
 (0)