Coverage for src / puzzletree / cli / messages / error.py: 100.00%
9 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-12 20:35 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-12 20:35 +0000
1"""CLI error message panels."""
3from rich.console import Console
4from rich.panel import Panel
5from rich.text import Text
7from puzzletree.cli.messages.capability import supports_unicode_markdown
10def error_panel(message: str, console: Console | None = None) -> Panel:
11 """Build a red Panel with title "Error" (optionally with Unicode when supported).
13 The message body is always rendered as plain Text, not Markdown, so file paths,
14 underscores, and special characters in user-provided error messages are not
15 interpreted as formatting.
17 Args:
18 message: The error message body.
19 console: Rich Console; when supported, title may use Unicode (e.g. ⚠).
20 Defaults to None.
22 Returns:
23 A red-bordered Panel suitable for console.print().
25 Examples:
26 Panel (plain text; terminal uses red border)::
28 ╭─ Error ────────────────────────────╮
29 │ Answers file not found: /path.yml │
30 ╰────────────────────────────────────╯
31 """
32 use_unicode = supports_unicode_markdown(console)
33 title = "⚠ Error" if use_unicode else "Error"
34 body = Text(message, style="red")
35 return Panel(body, title=title, border_style="red")