Coverage for aipyapp/cli/command/utils.py: 0%

1 from rich import print

2 from rich.table import Table

3 import random

4

5 from ... import T

6

7 COLORS = ["red", "green", "blue", "yellow", "magenta", "cyan", "white", "bright_red", "bright_green", "bright_blue", "bright_yellow", "bright_magenta", "bright_cyan"]

8

9 def print_table(rows, title=None, headers=None):

10 if not rows:

11 return

12 table = Table(title=title, show_lines=True)

13 for header in headers:

14 # 为每一列随机选择一个颜色

15 color = random.choice(COLORS)

16 table.add_column(T(header), justify="center", style=f"bold {color}", no_wrap=True)

17 for row in rows:

18 table.add_row(*[str(cell) for cell in row])

19 print(table)

20

21 def print_records(records, title=None):

22 if not records:

23 return

24 headers = type(records[0])._fields

25 print_table(records, title=title, headers=headers)