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

Fix console.capture context to not print empty line in jupyter #3474

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ 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).


## [13.9.5]

### Fixed
- Fixed `console.capture` context printing empty line in jupyter https://github.com/Textualize/rich/pull/3474

## [13.9.4] - 2024-11-01

### Changed
Expand Down
4 changes: 3 additions & 1 deletion rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,9 @@ def _write_buffer(self) -> None:
if self.is_jupyter: # pragma: no cover
from .jupyter import display

display(self._buffer, self._render_buffer(self._buffer[:]))
output = self._render_buffer(self._buffer[:])
if output and len(output) > 0:
display(self._buffer, output)
del self._buffer[:]
else:
if WINDOWS:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,14 @@ def test_force_color_jupyter():
assert not console.is_terminal


@mock.patch("rich.jupyter.display")
def test_capture_not_print_empty_line_jupyter(display: mock.MagicMock):
console = Console(force_jupyter=True)
with console.capture():
pass
display.assert_not_called()


def test_force_color():
console = Console(
file=io.StringIO(),
Expand Down