Added max height

This commit is contained in:
Will McGugan 2021-07-11 14:25:14 +01:00
parent 1e73828ec5
commit aba4c7b623
6 changed files with 11 additions and 3 deletions

View File

@ -142,8 +142,7 @@ class Align(JupyterMixin):
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)

View File

@ -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 @@ class ConsoleOptions:
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 @@ class 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 @@ class Console:
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,

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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,