Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The following people have contributed to the development of Rich:
- [Damian Shaw](https://github.com/notatallshaw)
- [Nicolas Simonds](https://github.com/0xDEC0DE)
- [Aaron Stephens](https://github.com/aaronst)
- [Stranger](https://github.com/Stranger-Jie)
- [Karolina Surma](https://github.com/befeleme)
- [Gabriele N. Tornetta](https://github.com/p403n1x87)
- [Nils Vu](https://github.com/nilsvu)
Expand Down
25 changes: 24 additions & 1 deletion rich/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .align import Align, AlignMethod
from .console import Console, ConsoleOptions, RenderableType, RenderResult
from .constrain import Constrain
from .measure import Measurement
from .measure import Measurement, measure_renderables
from .padding import Padding, PaddingDimensions
from .table import Table
from .text import TextType
Expand Down Expand Up @@ -170,6 +170,29 @@ def iter_renderables(
add_row(*row)
yield table

def __rich_measure__(
self, console: "Console", options: "ConsoleOptions"
) -> "Measurement":
title = self.title
_, right, _, left = Padding.unpack(self.padding)
padding = left + right
renderables = [*self.renderables, title] if title else [*self.renderables]

maximum_width = sum(
measure_renderables(
console,
options.update_width(options.max_width - padding - 2),
[renderable],
).maximum
for renderable in renderables
)

if self.width is None:
width = maximum_width + padding + 2
else:
width = self.width
return Measurement(width, width)


if __name__ == "__main__": # pragma: no cover
import os
Expand Down
5 changes: 5 additions & 0 deletions tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from rich.console import Console
from rich.columns import Columns
from rich.panel import Panel
from rich.segment import Segment
from rich.style import Style
Expand All @@ -16,6 +17,8 @@
Panel(Panel("Hello, World", padding=0), padding=0),
Panel("Hello, World", title="FOO", padding=0),
Panel("Hello, World", subtitle="FOO", padding=0),
Panel(Columns(["Hello", "World"]), padding=0),
Panel(Columns(["Hello", "World"]), expand=False, padding=0),
]

expected = [
Expand All @@ -26,6 +29,8 @@
"╭────────────────────────────────────────────────╮\n│╭──────────────────────────────────────────────╮│\n││Hello, World ││\n│╰──────────────────────────────────────────────╯│\n╰────────────────────────────────────────────────╯\n",
"╭───────────────────── FOO ──────────────────────╮\n│Hello, World │\n╰────────────────────────────────────────────────╯\n",
"╭────────────────────────────────────────────────╮\n│Hello, World │\n╰───────────────────── FOO ──────────────────────╯\n",
"╭────────────────────────────────────────────────╮\n│Hello World │\n╰────────────────────────────────────────────────╯\n",
"╭──────────────╮\n│Hello World │\n╰──────────────╯\n",
]


Expand Down