Skip to content

[BUG] Syntax wrapping doesn't account for padding #3727

Closed
@TomJGooding

Description

@TomJGooding

Describe the bug

I originally discovered this issue in Textual, but it looks like a possible bug in Syntax.

Here's a MRE with a narrow console width to demonstrate. The first syntax with wrapping enabled works as expected, however notice that the syntax with padding is missing some code:

from rich.console import Console
from rich.syntax import Syntax

EXAMPLE_CODE = """\
class ListViewExample(App):
    def compose(self) -> ComposeResult:
        yield ListView(
            ListItem(Label("One")),
            ListItem(Label("Two")),
            ListItem(Label("Three")),
        )
        yield Footer()\
"""

console = Console(width=32)

console.print("Syntax with wrapping enabled:", style="bold")
syntax = Syntax(EXAMPLE_CODE, lexer="python", word_wrap=True)
console.print(syntax)
console.print()

console.print("After adding padding:", style="bold")
syntax.padding = (1, 2)
console.print(syntax)

Tested with the latest version of rich (14.0.0) on Linux.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions