Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Fixed overriding the `background_color` of `Syntax` not including padding https://github.com/Textualize/rich/issues/3295

## [13.7.1] - 2023-02-28

### Fixed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The following people have contributed to the development of Rich:
- [Aryaz Eghbali](https://github.com/AryazE)
- [Oleksis Fraga](https://github.com/oleksis)
- [Andy Gimblett](https://github.com/gimbo)
- [Tom Gooding](https://github.com/TomJGooding)
- [Michał Górny](https://github.com/mgorny)
- [Nok Lam Chan](https://github.com/noklam)
- [Leron Gray](https://github.com/daddycocoaman)
Expand Down
4 changes: 1 addition & 3 deletions rich/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,7 @@ def __rich_console__(
) -> RenderResult:
segments = Segments(self._get_syntax(console, options))
if self.padding:
yield Padding(
segments, style=self._theme.get_background_style(), pad=self.padding
)
yield Padding(segments, style=self._get_base_style(), pad=self.padding)
else:
yield segments

Expand Down
17 changes: 17 additions & 0 deletions tests/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,23 @@ def test_syntax_measure():
assert code.__rich_measure__(console, console.options) == Measurement(3, 24)


def test_background_color_override_includes_padding():
"""Regression test for https://github.com/Textualize/rich/issues/3295"""

syntax = Syntax(
"x = 1",
lexer="python",
padding=(1, 3),
background_color="red",
)
result = render(syntax)
print(repr(result))
assert (
result
== "\x1b[41m \x1b[0m\n\x1b[41m \x1b[0m\x1b[38;2;248;248;242;41mx\x1b[0m\x1b[38;2;248;248;242;41m \x1b[0m\x1b[38;2;255;70;137;41m=\x1b[0m\x1b[38;2;248;248;242;41m \x1b[0m\x1b[38;2;174;129;255;41m1\x1b[0m\x1b[41m \x1b[0m\x1b[41m \x1b[0m\n\x1b[41m \x1b[0m\n"
)


if __name__ == "__main__":
syntax = Panel.fit(
Syntax(
Expand Down