-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[BUG] Right-justified panels with right-aligned titles display incorrectly #3641
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
Comments
example test def test_with_justify() -> None:
panel = Panel(
"Hello, World",
title="title",
subtitle="subtitle",
title_align="right",
)
console = Console(
file=io.StringIO(),
width=50,
height=20,
legacy_windows=False,
force_terminal=True,
color_system="truecolor",
)
console.print(panel, justify="right")
result = cleandoc(console.file.getvalue())
expected = cleandoc("""
╭────── title ─╮
│ Hello, World │
╰── subtitle ──╯
""")
assert result == expected |
Hey, I've taken a look at the issue and it appears to stem from containers.justify (specifically lines 139-142, where the trailing whitespace gets mistakenly rstrip'd and then padded to the beginning of the segment. If you need a fix: I've found that changing the line "line.rstrip()" to "line[:-1].rstrip()" prevents this behavior, and, at least in the case of the example you gave, solves the issue. This isn't an elegant solution, but seeing as the titles are padded with whitespace it may be "right." Checking tests, I don't see that this introduces regressions covered by the test. If @willmcgugan doesn't have an issue with it, I'll submit a pull request introducing the change. |
glad you found it! I spent about an hour looking for the cause but I'm not familiar with the code base. |
Describe the bug
a picture is worth a thousand words, the issue is the gap in the box
note: "a" is an extra gap and "b" the missing gap
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.
If you're using Rich in a terminal:
If you're using Rich in a Jupyter Notebook, run the following snippet in a cell
and paste the output in your bug report.
The text was updated successfully, but these errors were encountered: