|
| 1 | +# Display |
| 2 | + |
| 3 | +Utility Functions for Displaying Algorithm Information |
| 4 | + |
| 5 | +## def _supports_box_drawing() |
| 6 | + |
| 7 | +```python |
| 8 | +def _supports_box_drawing() -> bool |
| 9 | +``` |
| 10 | + |
| 11 | +Function to check if the terminal supports boxed characters. |
| 12 | + |
| 13 | +**Returns**: |
| 14 | + |
| 15 | +* ***bool*** (`bool`): True if the terminal likely supports boxed characters, False otherwise. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## class TableFormatter |
| 20 | + |
| 21 | +Class to format tabular data into strings for display in the console. |
| 22 | + |
| 23 | +**Parameters**: |
| 24 | + |
| 25 | +* ***headers*** (`Mapping[str, int]`): Mapping of column names to their respective widths, in the format `{column_name: column_width}`. |
| 26 | + |
| 27 | +**Raises**: |
| 28 | + |
| 29 | +* `ValueError`: If `headers` is empty or not a valid mapping. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +### def _border(left, middle, right, line, new_line=True) |
| 34 | + |
| 35 | +```python |
| 36 | +def _border(self, left: str, middle: str, right: str, line: str, new_line: bool = True) -> str |
| 37 | +``` |
| 38 | + |
| 39 | +Create a horizontal border for the table. |
| 40 | + |
| 41 | +**Parameters**: |
| 42 | + |
| 43 | +* ***left*** (`str`): Character on the left side of the border. |
| 44 | +* ***middle*** (`str`): Character separator between columns. |
| 45 | +* ***right*** (`str`): Character on the right side of the border. |
| 46 | +* ***line*** (`str`): Character used to fill the border. |
| 47 | +* ***new_line*** (`bool`, optional): If True, adds a line break before the border (default is True). |
| 48 | + |
| 49 | +**Returns**: |
| 50 | + |
| 51 | +* ***border*** (`str`): String representing the horizontal border. |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +### def get_header() |
| 56 | + |
| 57 | +```python |
| 58 | +def get_header(self) -> str |
| 59 | +``` |
| 60 | + |
| 61 | +Generate the table header, including the top border, column headings, and separator line. |
| 62 | + |
| 63 | +**Returns**: |
| 64 | + |
| 65 | +* ***header*** (`str`): Formatted string of the table header. |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +### def get_row(values) |
| 70 | + |
| 71 | +```python |
| 72 | +def get_row(self, values: Mapping[str, Union[str, int, float]]) -> str |
| 73 | +``` |
| 74 | + |
| 75 | +Generate a formatted row for the table data. |
| 76 | + |
| 77 | +**Parameters**: |
| 78 | + |
| 79 | +* ***values*** (`Mapping[str, Union[str, int, float]]`): Dictionary with values for each column, in the format `{column_name: value}`. |
| 80 | + |
| 81 | +**Returns**: |
| 82 | + |
| 83 | +* ***row*** (`str`): Formatted string of the table row. |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +### def get_bottom(new_line=False) |
| 88 | + |
| 89 | +```python |
| 90 | +def get_bottom(self, new_line: bool = False) -> str |
| 91 | +``` |
| 92 | + |
| 93 | +Generate the table's bottom border. |
| 94 | + |
| 95 | +**Parameters**: |
| 96 | + |
| 97 | +* ***new_line*** (`bool`, optional): If True, adds a line break before the border (default is False). |
| 98 | + |
| 99 | +**Returns**: |
| 100 | + |
| 101 | +* ***bottom*** (`str`): Formatted string for the bottom border. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## class ProgressTable(TableFormatter) |
| 106 | + |
| 107 | +Class to display a formatted table in the console to track the algorithm's progress. |
| 108 | + |
| 109 | +**Parameters**: |
| 110 | + |
| 111 | +* ***headers*** (`Mapping[str, int]`): Mapping `{column_name: column_width}`. |
| 112 | +* ***verbose*** (`bool`): If False, prints nothing to the terminal. |
| 113 | + |
| 114 | +**Raises**: |
| 115 | + |
| 116 | +* `ValueError`: If `headers` is empty or not a valid mapping. |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +### def _print_header() |
| 121 | + |
| 122 | +```python |
| 123 | +def _print_header(self) -> None |
| 124 | +``` |
| 125 | + |
| 126 | +Print the table header. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +### def update(values) |
| 131 | + |
| 132 | +```python |
| 133 | +def update(self, values: Mapping[str, Union[str, int, float]]) -> None |
| 134 | +``` |
| 135 | + |
| 136 | +Add a new row of values to the table. |
| 137 | + |
| 138 | +**Parameters**: |
| 139 | + |
| 140 | +* ***values*** (`Mapping[str, Union[str, int, float]]`): Keys must match the columns defined in headers. |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +### def finish() |
| 145 | + |
| 146 | +```python |
| 147 | +def finish(self) -> None |
| 148 | +``` |
| 149 | + |
| 150 | +End the table display, printing the bottom border and total time. |
| 151 | + |
| 152 | +--- |
0 commit comments