diff --git a/rich/align.py b/rich/align.py index d98d3c00..b1f9b3bb 100644 --- a/rich/align.py +++ b/rich/align.py @@ -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) diff --git a/rich/console.py b/rich/console.py index ca937e61..122f3c21 100644 --- a/rich/console.py +++ b/rich/console.py @@ -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, diff --git a/tests/test_box.py b/tests/test_box.py index f235a82e..21ba4fd0 100644 --- a/tests/test_box.py +++ b/tests/test_box.py @@ -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 diff --git a/tests/test_console.py b/tests/test_console.py index 771c07f9..3874d450 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -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, diff --git a/tests/test_live_render.py b/tests/test_live_render.py index 3a56fdd3..e8ae1108 100644 --- a/tests/test_live_render.py +++ b/tests/test_live_render.py @@ -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, diff --git a/tests/test_padding.py b/tests/test_padding.py index d4508e9f..7ab0d741 100644 --- a/tests/test_padding.py +++ b/tests/test_padding.py @@ -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,