Skip to content

Commit 15d5977

Browse files
authored
Merge pull request #3296 from TomJGooding/fix-syntax-include-padding-with-background-color-override
fix(syntax): include padding with background color override
2 parents fde5d6e + 9b4e3f1 commit 15d5977

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
98
## Unreleased
109

1110
### Fixed
@@ -16,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1615
- Thread used in progress.track will exit if an exception occurs in a generator https://github.com/Textualize/rich/pull/3402
1716
- Progress track thread is now a daemon thread https://github.com/Textualize/rich/pull/3402
1817
- Fixed cached hash preservation upon clearing meta and links https://github.com/Textualize/rich/issues/2942
18+
- Fixed overriding the `background_color` of `Syntax` not including padding https://github.com/Textualize/rich/issues/3295
1919

2020
### Changed
2121

@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131

3232
## [13.7.1] - 2024-02-28
3333

34+
3435
### Fixed
3536

3637
- Updated the widths of some characters https://github.com/Textualize/rich/pull/3289

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The following people have contributed to the development of Rich:
2020
- [Aryaz Eghbali](https://github.com/AryazE)
2121
- [Oleksis Fraga](https://github.com/oleksis)
2222
- [Andy Gimblett](https://github.com/gimbo)
23+
- [Tom Gooding](https://github.com/TomJGooding)
2324
- [Michał Górny](https://github.com/mgorny)
2425
- [Nok Lam Chan](https://github.com/noklam)
2526
- [Leron Gray](https://github.com/daddycocoaman)

rich/syntax.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,7 @@ def __rich_console__(
619619
) -> RenderResult:
620620
segments = Segments(self._get_syntax(console, options))
621621
if self.padding:
622-
yield Padding(
623-
segments, style=self._theme.get_background_style(), pad=self.padding
624-
)
622+
yield Padding(segments, style=self._get_base_style(), pad=self.padding)
625623
else:
626624
yield segments
627625

tests/test_syntax.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,23 @@ def test_syntax_measure():
406406
assert code.__rich_measure__(console, console.options) == Measurement(3, 24)
407407

408408

409+
def test_background_color_override_includes_padding():
410+
"""Regression test for https://github.com/Textualize/rich/issues/3295"""
411+
412+
syntax = Syntax(
413+
"x = 1",
414+
lexer="python",
415+
padding=(1, 3),
416+
background_color="red",
417+
)
418+
result = render(syntax)
419+
print(repr(result))
420+
assert (
421+
result
422+
== "\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"
423+
)
424+
425+
409426
if __name__ == "__main__":
410427
syntax = Panel.fit(
411428
Syntax(

0 commit comments

Comments
 (0)