Skip to content

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

@AaronBeaudoin

Description

@AaronBeaudoin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions