Skip to content

Commit 30e5ed6

Browse files
committed
fix(panel): fix title missing panel background
Fix `Panel` title missing the panel background style. This really just reverts the change in 7a38204. There's a history of issues related to the panel title styles, so I was careful to run all the examples in those issues to ensure there wasn't any regression. Fixes Textualize#3569
1 parent 69e1618 commit 30e5ed6

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ 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+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fixed `Panel` title missing the panel background style https://github.com/Textualize/rich/issues/3569
13+
814
## [14.0.0] - 2025-03-30
915

1016
### Added

rich/panel.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ def __rich_console__(
146146
Padding(self.renderable, _padding) if any(_padding) else self.renderable
147147
)
148148
style = console.get_style(self.style)
149-
partial_border_style = console.get_style(self.border_style)
150-
border_style = style + partial_border_style
149+
border_style = style + console.get_style(self.border_style)
151150
width = (
152151
options.max_width
153152
if self.width is None
@@ -206,7 +205,7 @@ def align_text(
206205

207206
title_text = self._title
208207
if title_text is not None:
209-
title_text.stylize_before(partial_border_style)
208+
title_text.stylize_before(border_style)
210209

211210
child_width = (
212211
width - 2
@@ -255,7 +254,7 @@ def align_text(
255254

256255
subtitle_text = self._subtitle
257256
if subtitle_text is not None:
258-
subtitle_text.stylize_before(partial_border_style)
257+
subtitle_text.stylize_before(border_style)
259258

260259
if subtitle_text is None or width <= 4:
261260
yield Segment(box.get_bottom([width - 2]), border_style)

tests/test_panel.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,30 @@ def test_title_text_with_border_color() -> None:
148148
assert result == expected
149149

150150

151+
def test_title_text_with_panel_background() -> None:
152+
"""Regression test for https://github.com/Textualize/rich/issues/3569"""
153+
panel = Panel(
154+
"Hello, World",
155+
style="on blue",
156+
title=Text("title", style="red"),
157+
subtitle=Text("subtitle", style="magenta bold"),
158+
)
159+
console = Console(
160+
file=io.StringIO(),
161+
width=50,
162+
height=20,
163+
legacy_windows=False,
164+
force_terminal=True,
165+
color_system="truecolor",
166+
)
167+
console.print(panel)
168+
169+
result = console.file.getvalue()
170+
print(repr(result))
171+
expected = "\x1b[44m╭─\x1b[0m\x1b[44m───────────────────\x1b[0m\x1b[31;44m title \x1b[0m\x1b[44m────────────────────\x1b[0m\x1b[44m─╮\x1b[0m\n\x1b[44m│\x1b[0m\x1b[44m \x1b[0m\x1b[44mHello, World\x1b[0m\x1b[44m \x1b[0m\x1b[44m \x1b[0m\x1b[44m│\x1b[0m\n\x1b[44m╰─\x1b[0m\x1b[44m──────────────────\x1b[0m\x1b[1;35;44m subtitle \x1b[0m\x1b[44m──────────────────\x1b[0m\x1b[44m─╯\x1b[0m\n"
172+
assert result == expected
173+
174+
151175
if __name__ == "__main__":
152176
expected = []
153177
for panel in tests:

0 commit comments

Comments
 (0)