2024-07-06 16:30:48 +00:00
|
|
|
from typing import Any, Dict, List, Optional
|
2024-07-06 16:26:36 +00:00
|
|
|
|
|
|
|
from rich.console import Console
|
|
|
|
from rich.table import Table
|
|
|
|
|
|
|
|
|
2024-07-06 16:30:48 +00:00
|
|
|
def print_rich_table(
|
|
|
|
tabular_data: List[Dict[str, Any]], headers: List[str], summary: Optional[str] = None
|
|
|
|
) -> None:
|
2024-07-06 16:26:36 +00:00
|
|
|
table = Table(title=summary)
|
|
|
|
|
|
|
|
for header in headers:
|
|
|
|
table.add_column(header, justify="right")
|
|
|
|
|
|
|
|
for row in tabular_data:
|
2024-07-06 16:30:48 +00:00
|
|
|
if isinstance(row, dict):
|
|
|
|
table.add_row(*[str(row[header]) for header in headers])
|
|
|
|
else:
|
|
|
|
table.add_row(*row)
|
2024-07-06 16:26:36 +00:00
|
|
|
|
|
|
|
console = Console()
|
|
|
|
console.print(table)
|