Format rows and headers into a table string.
(rows, headers)
| 1250 | |
| 1251 | |
| 1252 | def format_table(rows, headers): |
| 1253 | """Format rows and headers into a table string.""" |
| 1254 | if not rows: |
| 1255 | return "" |
| 1256 | |
| 1257 | # Calculate column widths |
| 1258 | widths = [len(h) for h in headers] |
| 1259 | for row in rows: |
| 1260 | for i, cell in enumerate(row): |
| 1261 | widths[i] = max(widths[i], len(str(cell))) |
| 1262 | |
| 1263 | # Create format string |
| 1264 | row_format = "│ " + " │ ".join(f"{{:<{w}}}" for w in widths) + " │" |
| 1265 | separator = "├─" + "─┼─".join("─" * w for w in widths) + "─┤" |
| 1266 | top_border = "┌─" + "─┬─".join("─" * w for w in widths) + "─┐" |
| 1267 | bottom_border = "└─" + "─┴─".join("─" * w for w in widths) + "─┘" |
| 1268 | |
| 1269 | # Build table |
| 1270 | table = [top_border, row_format.format(*headers), separator] |
| 1271 | for row in rows: |
| 1272 | table.append(row_format.format(*[str(cell) for cell in row])) |
| 1273 | table.append(bottom_border) |
| 1274 | |
| 1275 | return "\n".join(table) |
| 1276 | |
| 1277 | |
| 1278 | def parse_env_file(file_path: str) -> Dict[str, str]: |
no test coverage detected