Coverage for src / puzzletree / cli / messages / warning.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 warning 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 warning_panel(message: str, console: Console | None = None) -> Panel:
11 """Build a yellow Panel with title "Warning" (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 warning messages are not
15 interpreted as formatting.
17 Args:
18 message: The warning message body.
19 console: Rich Console; when supported, title may use Unicode (e.g. ⚠).
20 Defaults to None.
22 Returns:
23 A yellow-bordered Panel suitable for console.print().
25 Examples:
26 Panel (plain text; terminal uses yellow border)::
28 ╭─ Warning ─────────────────────────────╮
29 │ File already exists: /path/to/file │
30 │ Use --force to overwrite. │
31 ╰───────────────────────────────────────╯
32 """
33 use_unicode = supports_unicode_markdown(console)
34 title = "⚠ Warning" if use_unicode else "Warning"
35 body = Text(message, style="yellow")
36 return Panel(body, title=title, border_style="yellow")