diff --git a/CHANGELOG.md b/CHANGELOG.md index a5312c54..4ae80e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,11 +12,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed issue with Syntax and missing lines in Layout https://github.com/willmcgugan/rich/issues/1050 - Fixed issue with nested markdown elements https://github.com/willmcgugan/rich/issues/1036 - Fixed new lines not invoking render hooks https://github.com/willmcgugan/rich/issues/1052 +- Fixed Align setting height to child https://github.com/willmcgugan/rich/issues/1057 ### Changed - Printing a table with no columns now result in a blank line https://github.com/willmcgugan/rich/issues/1044 +### Added + +- Added height to Panel + ## [9.11.1] - 2021-02-20 ### Fixed diff --git a/rich/align.py b/rich/align.py index 05657d7b..edb3c8cd 100644 --- a/rich/align.py +++ b/rich/align.py @@ -138,7 +138,7 @@ class Align(JupyterMixin): Constrain( self.renderable, width if self.width is None else min(width, self.width) ), - options, + options.update(height=None), ) lines = list(Segment.split_lines(rendered)) width, height = Segment.get_shape(lines) diff --git a/rich/panel.py b/rich/panel.py index 38888ebd..f59331ad 100644 --- a/rich/panel.py +++ b/rich/panel.py @@ -30,6 +30,7 @@ class Panel(JupyterMixin): style (str, optional): The style of the panel (border and contents). Defaults to "none". border_style (str, optional): The style of the border. Defaults to "none". width (Optional[int], optional): Optional width of panel. Defaults to None to auto-detect. + height (Optional[int], optional): Optional height of panel. Defaults to None to auto-detect. padding (Optional[PaddingDimensions]): Optional padding around renderable. Defaults to 0. highlight (bool, optional): Enable automatic highlighting of panel title (if str). Defaults to False. """ @@ -46,6 +47,7 @@ class Panel(JupyterMixin): style: StyleType = "none", border_style: StyleType = "none", width: Optional[int] = None, + height: Optional[int] = None, padding: PaddingDimensions = (0, 1), highlight: bool = False, ) -> None: @@ -58,6 +60,7 @@ class Panel(JupyterMixin): self.style = style self.border_style = border_style self.width = width + self.height = height self.padding = padding self.highlight = highlight @@ -132,7 +135,9 @@ class Panel(JupyterMixin): if self.expand else Measurement.get(console, renderable, width - 2).maximum ) - child_height = None if options.height is None else options.height - 2 + child_height = self.height or options.height or None + if child_height: + child_height -= 2 if title_text is not None: child_width = min( options.max_width - 2, max(child_width, title_text.cell_len + 2)