mirror of https://github.com/Textualize/rich.git
Merge pull request #2088 from Textualize/panel-heading-glitch
panel bug
This commit is contained in:
commit
ef1b9b91cc
|
@ -1,14 +1,13 @@
|
||||||
from typing import Optional, TYPE_CHECKING
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from .box import Box, ROUNDED
|
|
||||||
|
|
||||||
from .align import AlignMethod
|
from .align import AlignMethod
|
||||||
|
from .box import ROUNDED, Box
|
||||||
from .jupyter import JupyterMixin
|
from .jupyter import JupyterMixin
|
||||||
from .measure import Measurement, measure_renderables
|
from .measure import Measurement, measure_renderables
|
||||||
from .padding import Padding, PaddingDimensions
|
from .padding import Padding, PaddingDimensions
|
||||||
|
from .segment import Segment
|
||||||
from .style import StyleType
|
from .style import StyleType
|
||||||
from .text import Text, TextType
|
from .text import Text, TextType
|
||||||
from .segment import Segment
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
||||||
|
@ -183,7 +182,7 @@ class Panel(JupyterMixin):
|
||||||
else:
|
else:
|
||||||
title_text.align(self.title_align, width - 4, character=box.top)
|
title_text.align(self.title_align, width - 4, character=box.top)
|
||||||
yield Segment(box.top_left + box.top, border_style)
|
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 Segment(box.top + box.top_right, border_style)
|
||||||
|
|
||||||
yield new_line
|
yield new_line
|
||||||
|
@ -202,7 +201,9 @@ class Panel(JupyterMixin):
|
||||||
else:
|
else:
|
||||||
subtitle_text.align(self.subtitle_align, width - 4, character=box.bottom)
|
subtitle_text.align(self.subtitle_align, width - 4, character=box.bottom)
|
||||||
yield Segment(box.bottom_left + box.bottom, border_style)
|
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 Segment(box.bottom + box.bottom_right, border_style)
|
||||||
|
|
||||||
yield new_line
|
yield new_line
|
||||||
|
@ -235,8 +236,8 @@ if __name__ == "__main__": # pragma: no cover
|
||||||
|
|
||||||
c = Console()
|
c = Console()
|
||||||
|
|
||||||
|
from .box import DOUBLE, ROUNDED
|
||||||
from .padding import Padding
|
from .padding import Padding
|
||||||
from .box import ROUNDED, DOUBLE
|
|
||||||
|
|
||||||
p = Panel(
|
p = Panel(
|
||||||
"Hello, World!",
|
"Hello, World!",
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import io
|
import io
|
||||||
from rich.console import Console
|
|
||||||
from rich.panel import Panel
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.panel import Panel
|
||||||
|
from rich.segment import Segment
|
||||||
|
from rich.style import Style
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
Panel("Hello, World", padding=0),
|
Panel("Hello, World", padding=0),
|
||||||
Panel("Hello, World", expand=False, padding=0),
|
Panel("Hello, World", expand=False, padding=0),
|
||||||
|
@ -52,6 +55,49 @@ def test_fixed_width():
|
||||||
assert max_width == 20
|
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__":
|
if __name__ == "__main__":
|
||||||
expected = []
|
expected = []
|
||||||
for panel in tests:
|
for panel in tests:
|
||||||
|
|
Loading…
Reference in New Issue