Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset height of children #2043

Merged
merged 8 commits into from Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions CHANGELOG.md
@@ -1,12 +1,11 @@

# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [12.0.0] - Unreleased

### Added

Expand All @@ -15,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added ProgressColumn `MofNCompleteColumn` to display raw `completed/total` column (similar to DownloadColumn,
but displays values as ints, does not convert to floats or add bit/bytes units).
https://github.com/Textualize/rich/pull/1941
- Remove Colorama dependency, call Windows Console API from Rich https://github.com/Textualize/rich/pull/1993
- Replace Colorama with win32 renderer https://github.com/Textualize/rich/pull/1993
- Add support for namedtuples to `Pretty` https://github.com/Textualize/rich/pull/2031

### Fixed
Expand All @@ -25,14 +24,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix syntax lexer guessing.
- Fixed Pretty measure not respecting expand_all https://github.com/Textualize/rich/issues/1998
- Collapsed definitions for single-character spinners, to save memory and reduce import time.
- Fix print_json indent type in __init__.py
- Fix print_json indent type in **init**.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly an issue but just curious - is this some markdown formatter thing that caused this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that may have been vscode. I need to put it inside backticks.

- Fix error when inspecting object defined in REPL https://github.com/Textualize/rich/pull/2037
- Fix incorrect highlighting of non-indented JSON https://github.com/Textualize/rich/pull/2038
- Fixed height reset in complex renderables https://github.com/Textualize/rich/issues/2042

### Changed

- Improved support for enum.Flag in ReprHighlighter https://github.com/Textualize/rich/pull/1920
- Tree now respects justify=None, i.e. won't pad to right https://github.com/Textualize/rich/issues/1690
- Removed rich.tabulate which was marked for deprecation
- Deprecated rich.align.AlignValues in favor of AlignMethod

## [11.2.0] - 2022-02-08

Expand Down Expand Up @@ -1661,7 +1663,7 @@ Major version bump for a breaking change to `Text.stylize signature`, which corr

- First official release, API still to be stabilized

[Unreleased]: https://github.com/willmcgugan/rich/compare/v11.0.0...HEAD
[unreleased]: https://github.com/willmcgugan/rich/compare/v11.0.0...HEAD
[11.2.0]: https://github.com/willmcgugan/rich/compare/v11.1.0...v11.2.0
[11.1.0]: https://github.com/willmcgugan/rich/compare/v11.0.0...v11.1.0
[11.0.0]: https://github.com/willmcgugan/rich/compare/v10.16.1...v11.0.0
Expand Down
1 change: 0 additions & 1 deletion rich/align.py
Expand Up @@ -18,7 +18,6 @@

AlignMethod = Literal["left", "center", "right"]
VerticalAlignMethod = Literal["top", "middle", "bottom"]
AlignValues = AlignMethod # TODO: deprecate AlignValues


class Align(JupyterMixin):
Expand Down
11 changes: 11 additions & 0 deletions rich/console.py
Expand Up @@ -224,6 +224,16 @@ def update_height(self, height: int) -> "ConsoleOptions":
options.max_height = options.height = height
return options

def reset_height(self) -> "ConsoleOptions":
"""Resets the height to None.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring makes it sound like the method is doing self.height = None

Suggested change
"""Resets the height to None.
"""Returns a copy of the ConsoleOptions with height=None

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

I had auto-merge on. Feel free to "request changes" if there is a worthwhile change.


Returns:
~ConsoleOptions: New console options instance.
"""
options = self.copy()
options.height = None
return options

def update_dimensions(self, width: int, height: int) -> "ConsoleOptions":
"""Update the width and height, and return a copy.

Expand Down Expand Up @@ -1245,6 +1255,7 @@ def render(
f"object {render_iterable!r} is not renderable"
)
_Segment = Segment
_options = _options.reset_height()
for render_output in iter_render:
if isinstance(render_output, _Segment):
yield render_output
Expand Down
1 change: 1 addition & 0 deletions rich/layout.py
Expand Up @@ -73,6 +73,7 @@ def __rich_console__(
style=self.style,
title=self.highlighter(title),
border_style="blue",
height=height,
)


Expand Down
51 changes: 0 additions & 51 deletions rich/tabulate.py

This file was deleted.

39 changes: 26 additions & 13 deletions tests/test_console.py
Expand Up @@ -308,7 +308,7 @@ def test_capture():


def test_input(monkeypatch, capsys):
def fake_input(prompt):
def fake_input(prompt=""):
console.file.write(prompt)
return "bar"

Expand All @@ -319,18 +319,6 @@ def fake_input(prompt):
assert user_input == "bar"


def test_input_legacy_windows(monkeypatch, capsys):
def fake_input(prompt):
console.file.write(prompt)
return "bar"

monkeypatch.setattr("builtins.input", fake_input)
console = Console(legacy_windows=True)
user_input = console.input(prompt="foo:")
assert capsys.readouterr().out == "foo:"
assert user_input == "bar"


def test_input_password(monkeypatch, capsys):
def fake_input(prompt, stream=None):
console.file.write(prompt)
Expand Down Expand Up @@ -768,3 +756,28 @@ def _mock_isatty():
def test_detect_color_system():
console = Console(_environ={"TERM": "rxvt-unicode-256color"}, force_terminal=True)
assert console._detect_color_system() == ColorSystem.EIGHT_BIT


def test_reset_height():
"""Test height is reset when rendering complex renderables."""
# https://github.com/Textualize/rich/issues/2042
class Panels:
def __rich_console__(self, console, options):
yield Panel("foo")
yield Panel("bar")

console = Console(
force_terminal=True,
color_system="truecolor",
width=20,
height=40,
legacy_windows=False,
)

with console.capture() as capture:
console.print(Panel(Panels()), height=12)
result = capture.get()
print(repr(result))
expected = "╭──────────────────╮\n│ ╭──────────────╮ │\n│ │ foo │ │\n│ ╰──────────────╯ │\n│ ╭──────────────╮ │\n│ │ bar │ │\n│ ╰──────────────╯ │\n│ │\n│ │\n│ │\n│ │\n╰──────────────────╯\n"

assert result == expected
34 changes: 0 additions & 34 deletions tests/test_tabulate.py

This file was deleted.