-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] text wrapping treats U+00A0 NO-WRAP SPACE as a regular space #3545
Comments
Apologies if this is unrelated but I have come across something similar when using tables and justification: from rich.console import Console
from rich.table import Table, Column
table = Table(Column(justify="right"), show_header=False)
table.add_row("hello\N{NO-BREAK SPACE}")
table.add_row("world")
console = Console()
console.print(table) which prints
whereas I was expecting something like:
Curiously, left justification works as I expected from rich.console import Console
from rich.table import Table, Column
table = Table(Column(justify="left"), show_header=False)
table.add_row("\N{NO-BREAK SPACE}hello")
table.add_row("world")
console = Console()
console.print(table)
|
@oir: it's a related, but different issue. Both issues stem from the fact that Python considers U+00A0 to be a space character, and so it gets matched by I've monkey-patched both bugs out in my current project with this: import re
from rich.text import Text
_re_whitespace = re.compile("[^\\S\N{NO-BREAK SPACE}]+$")
def monkeypatch_rich_word_wrapping_bug() -> None:
# Workaround for https://github.com/Textualize/rich/issues/3545
import rich._wrap
import rich.text
rich._wrap.re_word = re.compile("\\s*[\\S\N{NO-BREAK SPACE}]+\\s*")
rich.text._re_whitespace = _re_whitespace
def rstrip(self: Text) -> None:
self.plain = _re_whitespace.sub('', self.plain)
Text.rstrip = rstrip # type: ignore[method-assign] while waiting for feedback on #3571. |
Describe the bug
Here's a contrived example that demonstrates the issue:
It prints
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:
Platform
Click to expand
Ubuntu 24.10
GNOME Terminal 3.54.0 using VTE 0.78.0 +BIDI +GNUTLS +ICU +SYSTEMD
The text was updated successfully, but these errors were encountered: