Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- IPython now respects when a `Console` instance is passed to `pretty.install` https://github.com/Textualize/rich/pull/3915
- Fixed extraneous blank line on non-interactive disabled `Progress` https://github.com/Textualize/rich/pull/3905
- Fixed extra padding on first cell in columns https://github.com/Textualize/rich/pull/3935
- Fixed trailing whitespace removed when soft_wrap=True https://github.com/Textualize/rich/pull/3937

### Added

Expand All @@ -33,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed exception when callling `inspect` on objects with unusual `__qualname__` attribute https://github.com/Textualize/rich/pull/3894
- Fixed exception when calling `inspect` on objects with unusual `__qualname__` attribute https://github.com/Textualize/rich/pull/3894

## [14.1.0] - 2025-06-25

Expand Down
8 changes: 5 additions & 3 deletions rich/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,6 @@ def __rich_console__(
) -> Iterable[Segment]:
tab_size: int = console.tab_size if self.tab_size is None else self.tab_size
justify = self.justify or options.justify or DEFAULT_JUSTIFY

overflow = self.overflow or options.overflow or DEFAULT_OVERFLOW

lines = self.wrap(
Expand Down Expand Up @@ -1232,12 +1231,15 @@ def wrap(
if "\t" in line:
line.expand_tabs(tab_size)
if no_wrap:
if overflow == "ignore":
lines.append(line)
continue
new_lines = Lines([line])
else:
offsets = divide_line(str(line), width, fold=wrap_overflow == "fold")
new_lines = line.divide(offsets)
for line in new_lines:
line.rstrip_end(width)
for line in new_lines:
line.rstrip_end(width)
if wrap_justify:
new_lines.justify(
console, width, justify=wrap_justify, overflow=wrap_overflow
Expand Down
18 changes: 18 additions & 0 deletions tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,21 @@ def test_append_loop_regression() -> None:
b = Text("two", "blue")
b.append_text(b)
assert b.plain == "twotwo"


def test_soft_wrap() -> None:
"""Regression test for https://github.com/Textualize/rich/issues/3841

Soft wrap should not strip trailing whitespace.

"""
console = Console(color_system="standard", width=80, force_terminal=True)
text = Text(" Hello World ", style="white on blue")

with console.capture() as capture:
console.print(text, soft_wrap=True)

output = capture.get()
print(repr(output))
expected = "\x1b[37;44m Hello World \x1b[0m\n"
assert output == expected
Loading