|
1 | 1 | from math import ceil, floor |
2 | | -from typing import List, Optional, Union |
| 2 | +from typing import Any, List, Optional, Union |
3 | 3 |
|
4 | 4 | from .alignment import Alignment |
5 | 5 | from .options import Options |
@@ -93,27 +93,30 @@ def __auto_column_widths(self) -> List[int]: |
93 | 93 | column_widths = [] |
94 | 94 | for i in range(self.__columns): |
95 | 95 | # number of characters in column of i of header, each body row, and footer |
96 | | - header_size = len(self.__header[i]) if self.__header else 0 |
| 96 | + header_size = len(str(self.__header[i])) if self.__header else 0 |
97 | 97 | body_size = ( |
98 | | - map(lambda row, i=i: len(row[i]), self.__body) if self.__body else [0] |
| 98 | + map(lambda row, i=i: len(str(row[i])), self.__body) |
| 99 | + if self.__body |
| 100 | + else [0] |
99 | 101 | ) |
100 | | - footer_size = len(self.__footer[i]) if self.__footer else 0 |
| 102 | + footer_size = len(str(self.__footer[i])) if self.__footer else 0 |
101 | 103 | # get the max and add 2 for padding each side with a space |
102 | 104 | column_widths.append(max(header_size, *body_size, footer_size) + 2) |
103 | 105 | return column_widths |
104 | 106 |
|
105 | | - def __pad(self, text: str, width: int, alignment: Alignment) -> str: |
| 107 | + def __pad(self, cell_value: Any, width: int, alignment: Alignment) -> str: |
106 | 108 | """ |
107 | 109 | Pad a string of text to a given width with specified alignment |
108 | 110 |
|
109 | 111 | Args: |
110 | | - text (str): The text to pad |
| 112 | + cell_value (Any): The text in the cell to pad |
111 | 113 | width (int): The width in characters to pad to |
112 | 114 | alignment (Alignment): The alignment to use |
113 | 115 |
|
114 | 116 | Returns: |
115 | 117 | str: The padded text |
116 | 118 | """ |
| 119 | + text = str(cell_value) |
117 | 120 | if alignment == Alignment.LEFT: |
118 | 121 | # pad with spaces on the end |
119 | 122 | return f" {text} " + (" " * (width - len(text) - 2)) |
@@ -152,7 +155,7 @@ def __row_to_ascii( |
152 | 155 | if isinstance(filler, str) |
153 | 156 | # otherwise, use the column content |
154 | 157 | else self.__pad( |
155 | | - str(filler[i]), self.__column_widths[i], self.__alignments[i] |
| 158 | + filler[i], self.__column_widths[i], self.__alignments[i] |
156 | 159 | ) |
157 | 160 | ) |
158 | 161 | # column seperator |
|
0 commit comments