Improve rich tables interface

This commit is contained in:
Matthias
2024-07-06 20:59:50 +02:00
parent c9b3987d33
commit c296a8cf82

View File

@@ -1,3 +1,4 @@
import sys
from typing import Any, Dict, List, Optional
from rich.console import Console
@@ -5,9 +6,13 @@ from rich.table import Table
def print_rich_table(
tabular_data: List[Dict[str, Any]], headers: List[str], summary: Optional[str] = None
tabular_data: List[Dict[str, Any]],
headers: List[str],
summary: Optional[str] = None,
*,
table_kwargs: Optional[Dict[str, Any]] = None,
) -> None:
table = Table(title=summary)
table = Table(title=summary, **(table_kwargs or {}))
for header in headers:
table.add_column(header, justify="right")
@@ -18,5 +23,7 @@ def print_rich_table(
else:
table.add_row(*row)
console = Console()
console = Console(
width=200 if "pytest" in sys.modules else None,
)
console.print(table)