Skip to content

[BUG] Strings with ANSI escape sequences can cause Console.print() to hang #3958

@jmw182

Description

@jmw182

Describe the bug

While testing a rich-click app I discovered an issue I first reported (including example code) there: ewels/rich-click#325

I was inadvertently passing a string containing ANSI escape sequences (generated via rich-click) into Console.print(). Prior to the latest rich 14.3.2 this would print a mostly unformatted string including ANSI escape sequences (I understand that Text.from_ansi() would be required to handle the ANSI formatting).

With the latest "ZWJy release" 14.3.2, this now results in a hang as ANSI escape characters such as \x1b return a 0 from cells.get_character_cell_size(), resulting in an infinite loop in cells.split_graphemes(). Previously, \x1b would return a 1 and the string would print without hanging.

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

Windows 11, git-bash in Windows Terminal and VS Code Terminal. Python 3.14.3.

$ python -m rich.diagnose ╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ <console width=120 ColorSystem.TRUECOLOR> │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │ │ height = 30 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = True │ │ is_jupyter = False │ │ is_terminal = True │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=120, height=30), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=120, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=30, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=120, height=30) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 120 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮ │ Windows features available. │ │ │ │ ╭─────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │ │ ╰─────────────────────────────────────────────────╯ │ │ │ │ truecolor = True │ │ vt = True │ ╰─────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'CLICOLOR': None, │ │ 'COLORTERM': None, │ │ 'COLUMNS': None, │ │ 'JPY_PARENT_PID': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'LINES': None, │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': None, │ │ 'TERM': 'xterm-256color', │ │ 'TTY_COMPATIBLE': None, │ │ 'TTY_INTERACTIVE': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ platform="Windows" $ pip freeze | grep rich rich==14.3.2 rich-click==1.9.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions