chore: update rich-table print helper

This commit is contained in:
Matthias
2024-07-06 18:30:48 +02:00
parent 768a51cb9b
commit c9b3987d33
2 changed files with 9 additions and 4 deletions

View File

@@ -280,7 +280,7 @@ def start_list_markets(args: Dict[str, Any], pairs_only: bool = False) -> None:
writer.writeheader()
writer.writerows(tabular_data)
else:
print_rich_table(summary_str, headers, tabular_data)
print_rich_table(tabular_data, headers, summary_str)
elif not (
args.get("print_one_column", False)
or args.get("list_pairs_print_json", False)

View File

@@ -1,17 +1,22 @@
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional
from rich.console import Console
from rich.table import Table
def print_rich_table(summary: str, headers: List[str], tabular_data: List[Dict[str, Any]]) -> None:
def print_rich_table(
tabular_data: List[Dict[str, Any]], headers: List[str], summary: Optional[str] = None
) -> None:
table = Table(title=summary)
for header in headers:
table.add_column(header, justify="right")
for row in tabular_data:
table.add_row(*[str(row[header]) for header in headers])
if isinstance(row, dict):
table.add_row(*[str(row[header]) for header in headers])
else:
table.add_row(*row)
console = Console()
console.print(table)