44Rich TUI interface for bisect operations.
55
66This module provides a split-screen terminal UI for displaying bisect progress
7- and real-time command output. It gracefully falls back to plain text when
8- Rich is not available or when running in non-TTY environments .
7+ and real-time command output. It falls back to plain text when running in
8+ non-TTY environments or when Rich TUI is disabled via --no-tui .
99"""
1010
1111import re
1818if TYPE_CHECKING :
1919 from tritonparse .bisect .logger import BisectLogger
2020
21- # Graceful fallback if rich not installed
22- try :
23- from rich .console import Console
24- from rich .layout import Layout
25- from rich .live import Live
26- from rich .panel import Panel
27- from rich .text import Text
28-
29- RICH_AVAILABLE = True
30- except ImportError :
31- RICH_AVAILABLE = False
21+ from rich .console import Console
22+ from rich .layout import Layout
23+ from rich .live import Live
24+ from rich .panel import Panel
25+ from rich .text import Text
3226
3327# GitHub commit URL mapping - for generating clickable links
3428GITHUB_COMMIT_URLS = {
@@ -178,9 +172,6 @@ def __init__(self, enabled: bool = True) -> None:
178172 if not enabled :
179173 self ._rich_enabled = False
180174 self ._disabled_reason = "disabled by --no-tui flag"
181- elif not RICH_AVAILABLE :
182- self ._rich_enabled = False
183- self ._disabled_reason = "rich library not installed (pip install rich)"
184175 elif not sys .stdout .isatty () or not sys .stderr .isatty ():
185176 self ._rich_enabled = False
186177 self ._disabled_reason = "not running in a TTY (e.g., piped output or CI)"
@@ -576,11 +567,6 @@ def _parse_and_update_progress(self, line: str) -> None:
576567 self .update_progress (steps_remaining = steps_remaining )
577568
578569
579- def is_rich_available () -> bool :
580- """Check if Rich library is available."""
581- return RICH_AVAILABLE
582-
583-
584570def _generate_title (mode : SummaryMode , success : bool = True ) -> str :
585571 """
586572 Generate panel title based on mode.
@@ -618,6 +604,7 @@ def _print_pair_test_summary(
618604 command_log : Optional [str ],
619605 elapsed_time : Optional [float ],
620606 logger : Optional ["BisectLogger" ],
607+ use_rich : bool = True ,
621608) -> None :
622609 """
623610 Print pair test summary with Rich formatting (or plain text fallback).
@@ -630,8 +617,9 @@ def _print_pair_test_summary(
630617 command_log: Command log file path.
631618 elapsed_time: Total execution time in seconds.
632619 logger: Optional BisectLogger to write summary to log file.
620+ use_rich: Whether to use Rich formatting. If False, uses plain text.
633621 """
634- if RICH_AVAILABLE :
622+ if use_rich :
635623 console = Console (record = True )
636624 _print_pair_test_summary_rich (
637625 result , error_msg , log_dir , log_file , command_log , elapsed_time , console
@@ -853,6 +841,7 @@ def print_final_summary(
853841 command_log : Optional [str ] = None ,
854842 elapsed_time : Optional [float ] = None ,
855843 logger : Optional ["BisectLogger" ] = None ,
844+ use_rich : bool = True ,
856845) -> None :
857846 """
858847 Print final bisect summary with Rich formatting (or plain text fallback).
@@ -870,6 +859,7 @@ def print_final_summary(
870859 command_log: Command log file path (shown on error).
871860 elapsed_time: Total execution time in seconds.
872861 logger: Optional BisectLogger to write summary to log file.
862+ use_rich: Whether to use Rich formatting. If False, uses plain text.
873863 """
874864 # Handle pair test mode separately
875865 if mode == SummaryMode .PAIR_TEST :
@@ -881,6 +871,7 @@ def print_final_summary(
881871 command_log ,
882872 elapsed_time ,
883873 logger ,
874+ use_rich = use_rich ,
884875 )
885876 return
886877
@@ -897,7 +888,7 @@ def print_final_summary(
897888 and llvm_bump_info .is_llvm_bump
898889 )
899890
900- if RICH_AVAILABLE :
891+ if use_rich :
901892 # Use record=True to capture output for logging
902893 console = Console (record = True )
903894 _print_final_summary_rich (
0 commit comments