Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.6k stars 1.73k forks source link

[BUG] text wrapping treats U+00A0 NO-WRAP SPACE as a regular space #3545

Open mgedmin opened 2 weeks ago

mgedmin commented 2 weeks ago

Describe the bug

Here's a contrived example that demonstrates the issue:

from rich.console import Console
from rich.panel import Panel

console = Console()
text = 'A quick brown\N{NO-BREAK SPACE}fox jumps over the lazy dog.'
console.print(Panel(text, width=20))

It prints

╭──────────────────╮
│ A quick brown    │
│ fox jumps over   │
│ the lazy dog.    │
╰──────────────────╯

Observe how there's a line break between 'brown' and 'fox', despite the U+0020 NO-BREAK SPACE character. Apparently rich treats it like any other whitespace.

This is what I wanted to see:

╭──────────────────╮
│ A quick          │
│ brown fox jumps  │
│ over the lazy    │
│ dog.             │
╰──────────────────╯

Platform

Click to expand > What platform (Win/Linux/Mac) are you running on? Ubuntu 24.10 > What terminal software are you using? GNOME Terminal 3.54.0 using VTE 0.78.0 +BIDI +GNUTLS +ICU +SYSTEMD ```console $ python -m rich.diagnose ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 43 │ │ 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=190, height=43), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=190, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=43, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=190, height=43) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 190 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ Windows features available. │ │ │ │ ╭───────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ ╰───────────────────────────────────────────────────╯ │ │ │ │ truecolor = False │ │ vt = False │ ╰───────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': 'xterm-256color', │ │ 'COLORTERM': 'truecolor', │ │ 'CLICOLOR': None, │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': None, │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ platform="Linux" $ uv tree | grep rich ├── rich v13.8.1 ```
github-actions[bot] commented 2 weeks ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory