diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-12-23 18:53:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-12-23 18:53:19 +0000 |
commit | 38d39f536e5a6cff5a218c5dc16994d6eee087e9 (patch) | |
tree | 151b916ddadb35113bac2cd954d99ea26ec64cc0 /terminaltables3/ascii_table.py | |
parent | Updating source url in copyright. (diff) | |
download | terminaltables-38d39f536e5a6cff5a218c5dc16994d6eee087e9.tar.xz terminaltables-38d39f536e5a6cff5a218c5dc16994d6eee087e9.zip |
Merging upstream version 4.0.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | terminaltables3/ascii_table.py (renamed from terminaltables/ascii_table.py) | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/terminaltables/ascii_table.py b/terminaltables3/ascii_table.py index 3623918..4630f74 100644 --- a/terminaltables/ascii_table.py +++ b/terminaltables3/ascii_table.py @@ -1,8 +1,12 @@ """AsciiTable is the main table class. To be inherited by other tables. Define convenience methods here.""" -from terminaltables.base_table import BaseTable -from terminaltables.terminal_io import terminal_size -from terminaltables.width_and_alignment import column_max_width, max_dimensions, table_width +from terminaltables3.base_table import BaseTable +from terminaltables3.terminal_io import terminal_size +from terminaltables3.width_and_alignment import ( + column_max_width, + max_dimensions, + table_width, +) class AsciiTable(BaseTable): @@ -20,7 +24,7 @@ class AsciiTable(BaseTable): :ivar int padding_right: Number of spaces to pad on the right side of every cell. """ - def column_max_width(self, column_number): + def column_max_width(self, column_number: int) -> int: """Return the maximum width of a column based on the current terminal width. :param int column_number: The column number to query. @@ -32,24 +36,28 @@ class AsciiTable(BaseTable): outer_border = 2 if self.outer_border else 0 inner_border = 1 if self.inner_column_border else 0 padding = self.padding_left + self.padding_right - return column_max_width(inner_widths, column_number, outer_border, inner_border, padding) + return column_max_width( + inner_widths, column_number, outer_border, inner_border, padding + ) @property - def column_widths(self): + def column_widths(self) -> list[int]: """Return a list of integers representing the widths of each table column without padding.""" if not self.table_data: - return list() + return [] return max_dimensions(self.table_data)[0] @property - def ok(self): # Too late to change API. # pylint: disable=invalid-name + def ok(self) -> bool: # Too late to change API. # pylint: disable=invalid-name """Return True if the table fits within the terminal width, False if the table breaks.""" return self.table_width <= terminal_size()[0] @property - def table_width(self): + def table_width(self) -> int: """Return the width of the table including padding and borders.""" - outer_widths = max_dimensions(self.table_data, self.padding_left, self.padding_right)[2] + outer_widths = max_dimensions( + self.table_data, self.padding_left, self.padding_right + )[2] outer_border = 2 if self.outer_border else 0 inner_border = 1 if self.inner_column_border else 0 return table_width(outer_widths, outer_border, inner_border) |