Skip to content

Commit

Permalink
Merge branch 'master' into syntax-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed May 3, 2022
2 parents 199a791 + 5a999f4 commit b18d59f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,10 @@ 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

### Added

- Add `padding` to Syntax constructor https://github.com/Textualize/rich/pull/2247

## [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)

0 comments on commit b18d59f

Please sign in to comment.