Skip to content
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] Pretty width calculated incorrectly if expand_all is True #1998

Closed
AaronBeaudoin opened this issue Feb 24, 2022 · 1 comment · Fixed by #2002
Closed

[BUG] Pretty width calculated incorrectly if expand_all is True #1998

AaronBeaudoin opened this issue Feb 24, 2022 · 1 comment · Fixed by #2002
Labels
bug Something isn't working

Comments

@AaronBeaudoin
Copy link
Contributor

Describe the bug

If expand_all is True on a Pretty renderable, the width of the renderable seems to still be calculated as if expand_all was False. Here is a minimal example:

from rich.pretty import Pretty
from rich.panel import Panel
from rich import print

print(Panel(Pretty(["alpha"], expand_all=True), expand=False))
print(Panel(Pretty(["alpha", "beta"], expand_all=True), expand=False))
print(Panel(Pretty(["alpha", "beta", "delta"], expand_all=True), expand=False))
print(Panel(Pretty(["alpha", "beta", "delta", "gamma"], expand_all=True), expand=False))

And here is the output:

╭───────────╮
│ [         │
│     'alph │
│ a'        │
│ ]         │
╰───────────╯
╭───────────────────╮
│ [                 │
│     'alpha',      │
│     'beta'        │
│ ]                 │
╰───────────────────╯
╭────────────────────────────╮
│ [                          │
│     'alpha',               │
│     'beta',                │
│     'delta'                │
│ ]                          │
╰────────────────────────────╯
╭─────────────────────────────────────╮
│ [                                   │
│     'alpha',                        │
│     'beta',                         │
│     'delta',                        │
│     'gamma'                         │
│ ]                                   │
╰─────────────────────────────────────╯

The Panel is created with expand=False so it fits the content, but clearly the width of the Pretty output is incorrect because as you can see the panel does not really fit the output. In the first case the panel is too narrow, and as more elements are added it gets wider even though the actual rendered output is not getting wider.

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Mac, Default Terminal

@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants