diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c7332fee..359204cd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/rich/console.py b/rich/console.py index 3ec9a8aab..fd2ed5afe 100644 --- a/rich/console.py +++ b/rich/console.py @@ -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: diff --git a/tests/test_console.py b/tests/test_console.py index 407a138ec..4efe601a4 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -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(),