Merge pull request #387 from Honno/master

Change render_group's "fit" kwarg default from False to True
This commit is contained in:
Will McGugan 2020-10-16 14:48:24 +01:00 committed by GitHub
commit c8ed6bd065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dropped box.get_safe_box function in favor of Box.substitute
- Changed default padding in Panel from 0 to (0, 1) https://github.com/willmcgugan/rich/issues/385
- Table with row_styles will extend background color between cells if the box has no vertical dividerhttps://github.com/willmcgugan/rich/issues/383
- Changed default of fit kwarg in render_group() from False to True
- Renamed rich.bar to rich.progress_bar, and Bar class to ProgressBar, rich.bar is now the new solid bar class
### Fixed

View File

@ -245,7 +245,7 @@ class RenderGroup:
Args:
renderables (Iterable[RenderableType]): An iterable of renderable objects.
fit (bool, optional): Use the longest constituent renderable as the group's minimum width if ``True``, otherwise expand the group to fit the availabe space. Defaults to True.
"""
def __init__(self, *renderables: "RenderableType", fit: bool = True) -> None:
@ -271,8 +271,12 @@ class RenderGroup:
yield from self.renderables
def render_group(fit: bool = False) -> Callable:
"""A decorator that turns an iterable of renderables in to a group."""
def render_group(fit: bool = True) -> Callable:
"""A decorator that turns an iterable of renderables in to a group.
Args:
fit (bool, optional): Use the longest constituent renderable as the group's minimum width if ``True``, otherwise expand the group to fit the availabe space. Defaults to True.
"""
def decorator(method):
"""Convert a method that returns an iterable of renderables in to a RenderGroup."""

View File

@ -8,7 +8,8 @@ import pytest
from rich import errors
from rich.color import ColorSystem
from rich.console import CaptureError, Console, ConsoleOptions
from rich.console import CaptureError, Console, ConsoleOptions, render_group
from rich.measure import measure_renderables
from rich.pager import SystemPager
from rich.panel import Panel
from rich.style import Style
@ -377,3 +378,19 @@ def test_out() -> None:
console.begin_capture()
console.out(*(["foo bar"] * 5), sep=".", end="X")
assert console.end_capture() == "foo bar.foo bar.foo bar.foo bar.foo barX"
def test_render_group_fit() -> None:
@render_group()
def renderable():
yield "one"
yield "two"
yield "three" # <- largest width of 5
yield "four"
renderables = [renderable() for _ in range(4)]
console = Console(width=42)
min_width, _ = measure_renderables(console, renderables, 42)
assert min_width == 5