29
29
30
30
from .styles import DEFAULT_CMD2_STYLES
31
31
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" )
46
34
47
35
48
36
class AllowStyle (Enum ):
@@ -339,7 +327,7 @@ def prepare_objects_for_rendering(*objects: Any) -> tuple[Any, ...]:
339
327
"""Prepare a tuple of objects for printing by Rich's Console.print().
340
328
341
329
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
343
331
calculation, as Rich can then properly parse and account for these non-printing
344
332
codes. All other objects are left untouched, allowing Rich's native
345
333
renderers to handle them.
@@ -360,8 +348,8 @@ def prepare_objects_for_rendering(*objects: Any) -> tuple[Any, ...]:
360
348
361
349
renderable_as_str = str (renderable )
362
350
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 ):
365
353
object_list [i ] = string_to_rich_text (renderable_as_str )
366
354
367
355
return tuple (object_list )
0 commit comments