@@ -96,23 +96,20 @@ def __auto_column_widths(self) -> List[int]:
96
96
The minimum number of characters needed for each column
97
97
"""
98
98
99
- def widest_line (text : str ) -> int :
99
+ def widest_line (value : SupportsStr ) -> int :
100
100
"""Returns the width of the longest line in a multi-line string"""
101
+ text = str (value )
101
102
return max (len (line ) for line in text .splitlines ()) if len (text ) else 0
102
103
103
104
column_widths = []
104
105
# get the width necessary for each column
105
106
for i in range (self .__columns ):
106
- # col_widest returns the width of the widest line in the ith cell of a given list
107
- col_widest : Callable [[List [SupportsStr ], int ], int ] = lambda row , i = i : widest_line (
108
- str (row [i ])
109
- )
110
107
# number of characters in column of i of header, each body row, and footer
111
- header_size = col_widest (self .__header ) if self .__header else 0
112
- body_size = map ( col_widest , self .__body ) if self .__body else [ 0 ]
113
- footer_size = col_widest (self .__footer ) if self .__footer else 0
108
+ header_size = widest_line (self .__header [ i ] ) if self .__header else 0
109
+ body_size = max ( widest_line ( row [ i ]) for row in self .__body ) if self .__body else 0
110
+ footer_size = widest_line (self .__footer [ i ] ) if self .__footer else 0
114
111
# get the max and add 2 for padding each side with a space
115
- column_widths .append (max (header_size , * body_size , footer_size ) + 2 )
112
+ column_widths .append (max (header_size , body_size , footer_size ) + 2 )
116
113
return column_widths
117
114
118
115
def __pad (self , cell_value : SupportsStr , width : int , alignment : Alignment ) -> str :
0 commit comments