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

width param in RichLog.write isn't respected #4981

Closed
darrenburns opened this issue Sep 10, 2024 · 1 comment · Fixed by #4978
Closed

width param in RichLog.write isn't respected #4981

darrenburns opened this issue Sep 10, 2024 · 1 comment · Fixed by #4978
Assignees
Labels
bug Something isn't working

Comments

@darrenburns
Copy link
Member

All renderables written to RichLog seem to be rendered at min_width width, even if I specifically request a width in the write method.

I think width should always be respected if passed as an argument to write, and we only use the RichLog.min_width fallback when no width has been explicitly requested by the developer.

Example:

rich_log = RichLog()
rich_log.write(Panel(...), width=20)
# the panel is rendered 78 characters wide, not 20.

An MRE as a snapshot test:

def test_richlog_write_at_specific_width(snap_compare):
    """Ensure we can write renderables at a specific width."""

    class RichLogWriteAtSpecificWidth(App[None]):
        CSS = "RichLog { width: 53; background: $accent;}"

        def compose(self) -> ComposeResult:
            yield RichLog(min_width=50)

    async def run_before(pilot):
        rich_log: RichLog = pilot.app.query_one(RichLog)
        panel = Text("foo", style="black on red", justify="center")
        rich_log.write(panel, width=20)
        rich_log.write(panel, width=40)
        rich_log.write(panel, width=60)

    assert snap_compare(RichLogWriteAtSpecificWidth(), run_before=run_before)

Output:

image
@darrenburns darrenburns added the bug Something isn't working label Sep 10, 2024
@darrenburns darrenburns self-assigned this Sep 10, 2024
@darrenburns darrenburns mentioned this issue Sep 11, 2024
3 tasks
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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.

1 participant