Skip to content

[BUG] Overriding background_color of Syntax doesn't include padding #3295

@TomJGooding

Description

@TomJGooding

Describe the bug

See Textualize/textual#4227 (reply in thread) for context.

According to the Syntax documentation:

You can override the background color from the theme by supplying a background_color argument to the constructor.

However this doesn't seem to work as expected if the Syntax has padding:

image

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

code = """\
def do_something():
    pass\
"""

console = Console()

syntax = Syntax(
    code,
    lexer="python",
    word_wrap=False,
    indent_guides=True,
    padding=(1, 2),
    theme="material",
    background_color="red",
)

console.print(syntax)

If you set the background_color to the special value "default", this produces a different unexpected result:

image

Platform

Platform is Linux and tested in various terminal emulators.

$ pip freeze | grep rich
rich==13.6.0

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