Skip to content

Commit

Permalink
Merge pull request #2088 from Textualize/panel-heading-glitch
Browse files Browse the repository at this point in the history
panel bug
  • Loading branch information
willmcgugan committed Mar 21, 2022
2 parents a278b6e + 6d443dd commit ef1b9b9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
15 changes: 8 additions & 7 deletions rich/panel.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from typing import Optional, TYPE_CHECKING

from .box import Box, ROUNDED
from typing import TYPE_CHECKING, Optional

from .align import AlignMethod
from .box import ROUNDED, Box
from .jupyter import JupyterMixin
from .measure import Measurement, measure_renderables
from .padding import Padding, PaddingDimensions
from .segment import Segment
from .style import StyleType
from .text import Text, TextType
from .segment import Segment

if TYPE_CHECKING:
from .console import Console, ConsoleOptions, RenderableType, RenderResult
Expand Down Expand Up @@ -183,7 +182,7 @@ def __rich_console__(
else:
title_text.align(self.title_align, width - 4, character=box.top)
yield Segment(box.top_left + box.top, border_style)
yield from console.render(title_text)
yield from console.render(title_text, child_options.update_width(width - 4))
yield Segment(box.top + box.top_right, border_style)

yield new_line
Expand All @@ -202,7 +201,9 @@ def __rich_console__(
else:
subtitle_text.align(self.subtitle_align, width - 4, character=box.bottom)
yield Segment(box.bottom_left + box.bottom, border_style)
yield from console.render(subtitle_text)
yield from console.render(
subtitle_text, child_options.update_width(width - 4)
)
yield Segment(box.bottom + box.bottom_right, border_style)

yield new_line
Expand Down Expand Up @@ -235,8 +236,8 @@ def __rich_measure__(

c = Console()

from .box import DOUBLE, ROUNDED
from .padding import Padding
from .box import ROUNDED, DOUBLE

p = Panel(
"Hello, World!",
Expand Down
50 changes: 48 additions & 2 deletions tests/test_panel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import io
from rich.console import Console
from rich.panel import Panel

import pytest

from rich.console import Console
from rich.panel import Panel
from rich.segment import Segment
from rich.style import Style

tests = [
Panel("Hello, World", padding=0),
Panel("Hello, World", expand=False, padding=0),
Expand Down Expand Up @@ -52,6 +55,49 @@ def test_fixed_width():
assert max_width == 20


def test_render_size():
console = Console(width=63, height=46, legacy_windows=False)
options = console.options.update_dimensions(80, 4)
lines = console.render_lines(Panel("foo", title="Hello"), options=options)
print(repr(lines))
expected = [
[
Segment("╭─", Style()),
Segment(
"────────────────────────────────── Hello ───────────────────────────────────"
),
Segment("─╮", Style()),
],
[
Segment("│", Style()),
Segment(" ", Style()),
Segment("foo"),
Segment(
" "
),
Segment(" ", Style()),
Segment("│", Style()),
],
[
Segment("│", Style()),
Segment(" ", Style()),
Segment(
" ",
Style(),
),
Segment(" ", Style()),
Segment("│", Style()),
],
[
Segment(
"╰──────────────────────────────────────────────────────────────────────────────╯",
Style(),
)
],
]
assert lines == expected


if __name__ == "__main__":
expected = []
for panel in tests:
Expand Down

0 comments on commit ef1b9b9

Please sign in to comment.