Coverage for src / puzzletree / cli / messages / capability.py: 90.00%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-12 20:35 +0000

1"""CLI capability detection for Unicode and Markdown support.""" 

2 

3from rich.console import Console 

4 

5 

6def supports_unicode_markdown(console: Console | None) -> bool: 

7 """Return True when the console can safely display Unicode and Rich Markdown. 

8 

9 When True, message modules may use rich.markdown.Markdown and Unicode symbols 

10 (e.g. ✓, •, ⚠). When False, use plain Text and ASCII-only labels so output 

11 stays readable in CI, old terminals, or when piped. 

12 

13 Args: 

14 console: The Rich Console instance, or None. 

15 

16 Returns: 

17 True if encoding is UTF-8/UTF-16, not legacy Windows, and (optionally) 

18 writing to a terminal; otherwise False. 

19 """ 

20 if console is None: 

21 return False 

22 try: 

23 encoding = getattr(console, "encoding", None) or "" 

24 name = (encoding if isinstance(encoding, str) else getattr(encoding, "name", "") or "").lower() 

25 if not name.startswith("utf"): 

26 return False 

27 except (AttributeError, TypeError): 

28 return False 

29 if getattr(console, "legacy_windows", False): 

30 return False 

31 return getattr(console, "is_terminal", True)