|
1
|
"""Rich output helpers for the Boilerworks CLI.""" |
|
2
|
|
|
3
|
from __future__ import annotations |
|
4
|
|
|
5
|
from rich.console import Console |
|
6
|
from rich.panel import Panel |
|
7
|
from rich.table import Table |
|
8
|
from rich.text import Text |
|
9
|
|
|
10
|
from boilerworks.registry import TemplateInfo |
|
11
|
|
|
12
|
console = Console() |
|
13
|
|
|
14
|
|
|
15
|
_STATUS_STYLE: dict[str, str] = { |
|
16
|
"done": "bold green", |
|
17
|
"building": "bold yellow", |
|
18
|
"planned": "dim", |
|
19
|
} |
|
20
|
|
|
21
|
_SIZE_STYLE: dict[str, str] = { |
|
22
|
"full": "cyan", |
|
23
|
"micro": "magenta", |
|
24
|
"edge": "blue", |
|
25
|
} |
|
26
|
|
|
27
|
|
|
28
|
def _status_badge(status: str) -> Text: |
|
29
|
style = _STATUS_STYLE.get(status, "") |
|
30
|
labels = {"done": "● done", "building": "◐ building", "planned": "○ planned"} |
|
31
|
return Text(labels.get(status, status), style=style) |
|
32
|
|
|
33
|
|
|
34
|
def print_template_table(templates: list[TemplateInfo]) -> None: |
|
35
|
"""Print a Rich table of templates.""" |
|
36
|
if not templates: |
|
37
|
console.print("[yellow]No templates match your filters.[/yellow]") |
|
38
|
return |
|
39
|
|
|
40
|
table = Table( |
|
41
|
title=f"Boilerworks Templates ({len(templates)})", |
|
42
|
show_lines=False, |
|
43
|
header_style="bold white", |
|
44
|
border_style="dim", |
|
45
|
expand=False, |
|
46
|
) |
|
47
|
|
|
48
|
table.add_column("Name", style="bold", min_width=20) |
|
49
|
table.add_column("Size", min_width=6) |
|
50
|
table.add_column("Language", min_width=11) |
|
51
|
table.add_column("Backend", min_width=16) |
|
52
|
table.add_column("Frontend", min_width=16) |
|
53
|
table.add_column("Status", min_width=13) |
|
54
|
table.add_column("Description", min_width=30) |
|
55
|
|
|
56
|
for t in templates: |
|
57
|
size_text = Text(t.size, style=_SIZE_STYLE.get(t.size, "")) |
|
58
|
table.add_row( |
|
59
|
t.name, |
|
60
|
size_text, |
|
61
|
t.language, |
|
62
|
t.backend, |
|
63
|
t.frontend if t.frontend else "—", |
|
64
|
_status_badge(t.status), |
|
65
|
t.description, |
|
66
|
) |
|
67
|
|
|
68
|
console.print(table) |
|
69
|
|
|
70
|
|
|
71
|
def print_template_detail(template: TemplateInfo) -> None: |
|
72
|
"""Print a Rich panel with full template details.""" |
|
73
|
lines = [ |
|
74
|
f"[bold]Name:[/bold] {template.name}", |
|
75
|
f"[bold]Repo:[/bold] {template.repo}", |
|
76
|
f"[bold]Size:[/bold] {template.size}", |
|
77
|
f"[bold]Language:[/bold] {template.language}", |
|
78
|
f"[bold]Backend:[/bold] {template.backend}", |
|
79
|
f"[bold]Frontend:[/bold] {template.frontend or '—'}", |
|
80
|
f"[bold]Status:[/bold] {template.status}", |
|
81
|
f"[bold]Topologies:[/bold] {', '.join(template.topologies)}", |
|
82
|
"", |
|
83
|
f"[bold]Best for:[/bold] {template.best_for}", |
|
84
|
f"[bold]Description:[/bold] {template.description}", |
|
85
|
] |
|
86
|
console.print(Panel("\n".join(lines), title=f"[bold cyan]{template.name}[/bold cyan]", border_style="cyan")) |
|
87
|
|
|
88
|
|
|
89
|
def print_success(message: str) -> None: |
|
90
|
"""Print a success message.""" |
|
91
|
console.print(f"[bold green]✓[/bold green] {message}") |
|
92
|
|
|
93
|
|
|
94
|
def print_error(message: str) -> None: |
|
95
|
"""Print an error message.""" |
|
96
|
console.print(f"[bold red]✗[/bold red] {message}") |
|
97
|
|
|
98
|
|
|
99
|
def print_info(message: str) -> None: |
|
100
|
"""Print an informational message.""" |
|
101
|
console.print(f"[dim]→[/dim] {message}") |
|
102
|
|
|
103
|
|
|
104
|
def print_warning(message: str) -> None: |
|
105
|
"""Print a warning message.""" |
|
106
|
console.print(f"[bold yellow]![/bold yellow] {message}") |
|
107
|
|