You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using console.capture() in Jupyter, a new line gets printed to the notebook when exiting the capture context. This is unexpected, and is also different from rich's behavior in terminal (no new lines printed).
Here's a minimal example. After running the following in a Jupyter cell, 100 new lines are printed:
import rich.console
console = rich.console.Console()
for _ in range(100):
with console.capture() as capture:
console.print(1)
I think the issue is within Console._check_buffer. When exiting a capture context, self._render_buffer(self._buffer[:]) returns an empty string. When not in Jupyter, we eventually call self.file.write which is no-op when the text is empty. However, in Jupyter we'd call IPython.display.display, which IIUC always results in an empty line.
Describe the bug
When using
console.capture()
in Jupyter, a new line gets printed to the notebook when exiting the capture context. This is unexpected, and is also different fromrich
's behavior in terminal (no new lines printed).Here's a minimal example. After running the following in a Jupyter cell, 100 new lines are printed:
I think the issue is within
Console._check_buffer
. When exiting a capture context,self._render_buffer(self._buffer[:])
returns an empty string. When not in Jupyter, we eventually callself.file.write
which is no-op when the text is empty. However, in Jupyter we'd callIPython.display.display
, which IIUC always results in an empty line.rich/rich/console.py
Lines 2003 to 2066 in 26152e9
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.
If you're using Rich in a terminal:
If you're using Rich in a Jupyter Notebook, run the following snippet in a cell
and paste the output in your bug report.
The text was updated successfully, but these errors were encountered: