mirror of
https://github.com/Textualize/rich.git
synced 2026-02-06 10:58:48 +00:00
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 #3569
This commit is contained in:
parent
69e1618f1f
commit
30e5ed61a6
@ -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 `Panel` title missing the panel background style https://github.com/Textualize/rich/issues/3569
|
||||
|
||||
## [14.0.0] - 2025-03-30
|
||||
|
||||
### Added
|
||||
|
||||
@ -146,8 +146,7 @@ class Panel(JupyterMixin):
|
||||
Padding(self.renderable, _padding) if any(_padding) else self.renderable
|
||||
)
|
||||
style = console.get_style(self.style)
|
||||
partial_border_style = console.get_style(self.border_style)
|
||||
border_style = style + partial_border_style
|
||||
border_style = style + console.get_style(self.border_style)
|
||||
width = (
|
||||
options.max_width
|
||||
if self.width is None
|
||||
@ -206,7 +205,7 @@ class Panel(JupyterMixin):
|
||||
|
||||
title_text = self._title
|
||||
if title_text is not None:
|
||||
title_text.stylize_before(partial_border_style)
|
||||
title_text.stylize_before(border_style)
|
||||
|
||||
child_width = (
|
||||
width - 2
|
||||
@ -255,7 +254,7 @@ class Panel(JupyterMixin):
|
||||
|
||||
subtitle_text = self._subtitle
|
||||
if subtitle_text is not None:
|
||||
subtitle_text.stylize_before(partial_border_style)
|
||||
subtitle_text.stylize_before(border_style)
|
||||
|
||||
if subtitle_text is None or width <= 4:
|
||||
yield Segment(box.get_bottom([width - 2]), border_style)
|
||||
|
||||
@ -148,6 +148,30 @@ def test_title_text_with_border_color() -> None:
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_title_text_with_panel_background() -> None:
|
||||
"""Regression test for https://github.com/Textualize/rich/issues/3569"""
|
||||
panel = Panel(
|
||||
"Hello, World",
|
||||
style="on blue",
|
||||
title=Text("title", style="red"),
|
||||
subtitle=Text("subtitle", style="magenta bold"),
|
||||
)
|
||||
console = Console(
|
||||
file=io.StringIO(),
|
||||
width=50,
|
||||
height=20,
|
||||
legacy_windows=False,
|
||||
force_terminal=True,
|
||||
color_system="truecolor",
|
||||
)
|
||||
console.print(panel)
|
||||
|
||||
result = console.file.getvalue()
|
||||
print(repr(result))
|
||||
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"
|
||||
assert result == expected
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
expected = []
|
||||
for panel in tests:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user