Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render height fix #2246

Merged
merged 6 commits into from May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Change SVG export to create a simpler SVG
- Fix render_lines crash when render height was negative https://github.com/Textualize/rich/pull/2246

## [12.3.0] - 2022-04-26

Expand Down
7 changes: 6 additions & 1 deletion rich/console.py
Expand Up @@ -1327,6 +1327,11 @@ def render_lines(
_rendered = self.render(renderable, render_options)
if style:
_rendered = Segment.apply_style(_rendered, style)

render_height = render_options.height
if render_height is not None:
render_height = max(0, render_height)

lines = list(
islice(
Segment.split_and_crop_lines(
Expand All @@ -1336,7 +1341,7 @@ def render_lines(
pad=pad,
),
None,
render_options.height,
render_height,
)
)
if render_options.height is not None:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_console.py
Expand Up @@ -20,6 +20,7 @@
)
from rich.control import Control
from rich.measure import measure_renderables
from rich.padding import Padding
from rich.pager import SystemPager
from rich.panel import Panel
from rich.region import Region
Expand Down Expand Up @@ -862,3 +863,18 @@ def __rich_console__(self, console, options):
expected = "╭──────────────────╮\n│ ╭──────────────╮ │\n│ │ foo │ │\n│ ╰──────────────╯ │\n│ ╭──────────────╮ │\n│ │ bar │ │\n│ ╰──────────────╯ │\n│ │\n│ │\n│ │\n│ │\n╰──────────────────╯\n"

assert result == expected


def test_render_lines_height_minus_vertical_pad_is_negative():
# https://github.com/Textualize/textual/issues/389
console = Console(
force_terminal=True,
color_system="truecolor",
width=20,
height=40,
legacy_windows=False,
)
options = console.options.update_height(1)

# Ensuring that no exception is raised...
console.render_lines(Padding("hello", pad=(1, 0)), options=options)