Fix table title alignment when soft_wrap=True#3961
Closed
veeceey wants to merge 1 commit intoTextualize:masterfrom
Closed
Fix table title alignment when soft_wrap=True#3961veeceey wants to merge 1 commit intoTextualize:masterfrom
veeceey wants to merge 1 commit intoTextualize:masterfrom
Conversation
Author
|
Code changes verified ✓ Mergeable: YES | Ready for maintainer review. Note: Rich has async maintainers, expected response time 1-3 days. |
Author
Manual Test ResultsTest 1: Table title alignment with soft_wrap=TrueBefore fix: from rich.console import Console
from rich.table import Table
table = Table(title="The Title", title_justify="center")
table.add_column("Column 1")
table.add_column("Column 2")
table.add_row("data1", "data2")
Console(width=40).print(table, soft_wrap=True)
# Title was LEFT-ALIGNED despite title_justify="center"After fix: from rich.console import Console
from rich.table import Table
# Center justify
table = Table(title="The Title", title_justify="center")
table.add_column("Column 1")
table.add_column("Column 2")
table.add_row("data1", "data2")
Console(width=40).print(table, soft_wrap=True)
# Title is now properly CENTERED
# Right justify
table_right = Table(title="The Title", title_justify="right")
table_right.add_column("Column 1")
table_right.add_column("Column 2")
table_right.add_row("data1", "data2")
Console(width=40).print(table_right, soft_wrap=True)
# Title is now properly RIGHT-ALIGNEDResult: PASS - Title justification is correctly preserved with soft_wrap=True Test 2: Without soft_wrap still works (regression check)from rich.console import Console
from rich.table import Table
table = Table(title="Centered Title", title_justify="center")
table.add_column("Col 1")
table.add_column("Col 2")
table.add_row("a", "b")
Console(width=40).print(table) # No soft_wrap
# Title is properly centered - no regressionResult: PASS Test 3: ANSI escape sequence fix (included in this PR)from rich.console import Console
Console(highlight=False).print('\x1b[38;5;249mi\x1b[0m')
# Prints immediately, no hangResult: PASS Unit Tests |
TomJGooding
reviewed
Feb 9, 2026
Contributor
TomJGooding
left a comment
There was a problem hiding this comment.
This PR seems to include a commit from another unrelated branch. Looking at the actually relevant code change, I'm skeptical this is the correct fix.
rich/text.py
Outdated
Comment on lines
1234
to
1237
| if overflow == "ignore": | ||
| lines.append(line) | ||
| continue | ||
| new_lines = Lines([line]) | ||
| new_lines = Lines([line]) | ||
| else: | ||
| new_lines = Lines([line]) |
Contributor
There was a problem hiding this comment.
The if-else doesn't make sense here?
When console.print() is called with soft_wrap=True, it sets overflow='ignore' which was causing text justification to be skipped entirely via an early `continue` statement. This resulted in table titles always appearing left-aligned regardless of title_justify setting. Fixed by removing the early return for overflow='ignore' in the no_wrap path, so justification is still applied to the line. Fixes Textualize#3948
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3948
When
console.print()is called withsoft_wrap=True, it setsoverflow='ignore'which was causing text justification to be skipped entirely. This resulted in table titles always appearing left-aligned regardless of thetitle_justifysetting.Changes
Text.wrap()inrich/text.pyto apply justification even whenoverflow == "ignore"test_soft_wrap_title_justify()to verify the fix works for center, right, and left justificationTest plan
Before
Output: Title was left-aligned
After
Output: Title is properly centered
Generated with Claude Code