Coverage for src / puzzletree / cli / messages / layout.py: 100.00%

6 statements  

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

1"""CLI layout utilities for Rich multi-panel output. 

2 

3Provides use_layout to decide when to use Layout-based output for wide terminals 

4vs single-panel output for narrow terminals or piped output. 

5""" 

6 

7from rich.console import Console 

8 

9 

10def use_layout(console: Console | None, min_width: int = 100) -> bool: 

11 """Return True when Layout should be used instead of single-panel output. 

12 

13 Uses Layout when the console is wide enough; otherwise falls back to 

14 single-panel layout to avoid cramped output. 

15 

16 Args: 

17 console: The Rich Console instance, or None. 

18 min_width: Minimum console width (in characters) to use Layout. 

19 Defaults to 100. 

20 

21 Returns: 

22 True if Layout should be used; False for single-panel fallback. 

23 """ 

24 if console is None: 

25 return False 

26 width = getattr(console, "width", None) 

27 return not (width is None or width < min_width)