Skip to content

Commit

Permalink
Added max height
Browse files Browse the repository at this point in the history
willmcgugan committed Jul 11, 2021
1 parent 1e73828 commit aba4c7b
Showing 6 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions rich/align.py
Original file line number Diff line number Diff line change
@@ -142,8 +142,7 @@ def __rich_console__(
Constrain(
self.renderable, width if self.width is None else min(width, self.width)
),
options
# options.update(height=self.height or options.height or 1),
options.update(height=None),
)
lines = list(Segment.split_lines(rendered))
width, height = Segment.get_shape(lines)
7 changes: 6 additions & 1 deletion rich/console.py
Original file line number Diff line number Diff line change
@@ -134,6 +134,8 @@ class ConsoleOptions:
"""True if the target is a terminal, otherwise False."""
encoding: str
"""Encoding of terminal."""
max_height: int
"""Height of container (starts as terminal)"""
justify: Optional[JustifyMethod] = None
"""Justify value override for renderable."""
overflow: Optional[OverflowMethod] = None
@@ -145,7 +147,6 @@ class ConsoleOptions:
markup: Optional[bool] = None
"""Enable markup when rendering strings."""
height: Optional[int] = None
"""Height available, or None for no height limit."""

@property
def ascii_only(self) -> bool:
@@ -194,6 +195,8 @@ def update(
if not isinstance(markup, NoChange):
options.markup = markup
if not isinstance(height, NoChange):
if height is not None:
options.max_height = height
options.height = None if height is None else max(0, height)
return options

@@ -223,6 +226,7 @@ def update_dimensions(self, width: int, height: int) -> "ConsoleOptions":
options = self.copy()
options.min_width = options.max_width = max(0, width)
options.height = height
options.max_height = height
return options


@@ -907,6 +911,7 @@ def is_dumb_terminal(self) -> bool:
def options(self) -> ConsoleOptions:
"""Get default console options."""
return ConsoleOptions(
max_height=self.size.height,
size=self.size,
legacy_windows=self.legacy_windows,
min_width=1,
1 change: 1 addition & 0 deletions tests/test_box.py
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ def test_box_substitute():
max_width=100,
is_terminal=True,
encoding="utf-8",
max_height=25,
)
assert HEAVY.substitute(options) == SQUARE

1 change: 1 addition & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ def test_truecolor_terminal():
def test_console_options_update():
options = ConsoleOptions(
ConsoleDimensions(80, 25),
max_height=25,
legacy_windows=False,
min_width=10,
max_width=20,
1 change: 1 addition & 0 deletions tests/test_live_render.py
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ def test_restore_cursor(live_render):
def test_rich_console(live_render):
options = ConsoleOptions(
ConsoleDimensions(80, 25),
max_height=25,
legacy_windows=False,
min_width=10,
max_width=20,
1 change: 1 addition & 0 deletions tests/test_padding.py
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ def test_rich_console():
style = Style(color="red")
options = ConsoleOptions(
ConsoleDimensions(80, 25),
max_height=25,
legacy_windows=False,
min_width=10,
max_width=20,

0 comments on commit aba4c7b

Please sign in to comment.