2929
3030from .styles import DEFAULT_CMD2_STYLES
3131
32- # A compiled regular expression to detect ANSI escape sequences.
33- _ANSI_ESCAPE_SEQUENCE_RE = re .compile (
34- r"""
35- \x1b # Match the Escape character (ESC)
36- (?: # Start of non-capturing group for the different sequence types
37- \[[0-9;?]*[a-zA-Z] # Match a CSI sequence (e.g., \x1b[31m)
38- | # OR
39- \].*?(?:\x07|\x1b\x5c) # Match an OSC sequence (e.g., \x1b]2;Hello\x07)
40- | # OR
41- \x37|\x38 # Match DEC cursor save/restore sequences
42- ) # End of non-capturing group
43- """ ,
44- re .VERBOSE ,
45- )
32+ # A compiled regular expression to detect ANSI style sequences.
33+ ANSI_STYLE_SEQUENCE_RE = re .compile (r"\x1b\[[0-9;?]*m" )
4634
4735
4836class AllowStyle (Enum ):
@@ -339,7 +327,7 @@ def prepare_objects_for_rendering(*objects: Any) -> tuple[Any, ...]:
339327 """Prepare a tuple of objects for printing by Rich's Console.print().
340328
341329 This function converts any non-Rich object whose string representation contains
342- ANSI escape sequences into a rich.Text object. This ensures correct display width
330+ ANSI style sequences into a rich.Text object. This ensures correct display width
343331 calculation, as Rich can then properly parse and account for these non-printing
344332 codes. All other objects are left untouched, allowing Rich's native
345333 renderers to handle them.
@@ -360,8 +348,8 @@ def prepare_objects_for_rendering(*objects: Any) -> tuple[Any, ...]:
360348
361349 renderable_as_str = str (renderable )
362350
363- # Check for any ANSI escape sequences in the string.
364- if _ANSI_ESCAPE_SEQUENCE_RE .search (renderable_as_str ):
351+ # Check for any ANSI style sequences in the string.
352+ if ANSI_STYLE_SEQUENCE_RE .search (renderable_as_str ):
365353 object_list [i ] = string_to_rich_text (renderable_as_str )
366354
367355 return tuple (object_list )
0 commit comments