rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Using status overwrites all previous output when in Jupyter notebook

Open ggydush-fn opened this issue 2 years ago • 4 comments

Describe the bug

When in a Jupyter notebook, using status overwrites all previous output.

import time

from rich.console import Console

print("Previous output")
console = Console()

with console.status('This overwrites previous output'):
    time.sleep(2)

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:

╭────────────────────── <class 'rich.console.Console'> ──────────────────────╮
│ A high level console interface.                                            │
│                                                                            │
│ ╭────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=93 ColorSystem.TRUECOLOR>                               │ │
│ ╰────────────────────────────────────────────────────────────────────────╯ │
│                                                                            │
│     color_system = 'truecolor'                                             │
│         encoding = 'utf-8'                                                 │
│             file = <ipykernel.iostream.OutStream object at 0x7f9c0ea1eb20> │
│           height = 100                                                     │
│    is_alt_screen = False                                                   │
│ is_dumb_terminal = False                                                   │
│   is_interactive = False                                                   │
│       is_jupyter = True                                                    │
│      is_terminal = False                                                   │
│   legacy_windows = False                                                   │
│         no_color = False                                                   │
│          options = ConsoleOptions(                                         │
│                        size=ConsoleDimensions(width=93, height=100),       │
│                        legacy_windows=False,                               │
│                        min_width=1,                                        │
│                        max_width=93,                                       │
│                        is_terminal=False,                                  │
│                        encoding='utf-8',                                   │
│                        max_height=100,                                     │
│                        justify=None,                                       │
│                        overflow=None,                                      │
│                        no_wrap=False,                                      │
│                        highlight=None,                                     │
│                        markup=None,                                        │
│                        height=None                                         │
│                    )                                                       │
│            quiet = False                                                   │
│           record = False                                                   │
│         safe_box = True                                                    │
│             size = ConsoleDimensions(width=93, height=100)                 │
│        soft_wrap = False                                                   │
│           stderr = False                                                   │
│            style = None                                                    │
│         tab_size = 8                                                       │
│            width = 93                                                      │
╰────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-color',         │
│     'COLORTERM': None,             │
│     'CLICOLOR': '1',               │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JPY_PARENT_PID': '53',        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"

ggydush-fn avatar Mar 25 '22 16:03 ggydush-fn

Please post output of

from rich.diagnose import report
report()

USLTD avatar Mar 25 '22 16:03 USLTD

@UltraStudioLTD Updated the Platform section!

ggydush-fn avatar Mar 25 '22 16:03 ggydush-fn

@ggydush-fn Can you try in Jupyter lab. There are API differences in Jupyter Lab and Jupyter Notebook, which unfortunately there is not much we can do about.

willmcgugan avatar Mar 26 '22 12:03 willmcgugan

@willmcgugan Thanks for getting back and you were right on target there! Bummer about the API differences and not having much control over it, but appreciate you taking a look!

Just in case anyone gets here down the road:

I tried this on JupyterHub and it looked like the following (previous text is overwritten):

https://user-images.githubusercontent.com/69013027/160244093-b0a7a3f0-5741-4b67-8425-33e61ee04393.mov

Whereas on JupyterLab in a fresh environment (and in Vscode's notebooks), the previous text was kept:

https://user-images.githubusercontent.com/69013027/160244099-b824bc7a-f13c-4d71-a452-1e00f4fc9536.mov

ggydush-fn avatar Mar 26 '22 14:03 ggydush-fn

I also encounter this issue or at least very similar. I can replicate this with the status sample. All output from console.log (except 'task 10 complete') is removed: image

When run in a jupyter terminal, I do get the behaviour I expect: image

Output of rich.diagnose.report:
╭────────────────────── <class 'rich.console.Console'> ──────────────────────╮
│ A high level console interface.                                            │
│                                                                            │
│ ╭────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=115 ColorSystem.TRUECOLOR>                              │ │
│ ╰────────────────────────────────────────────────────────────────────────╯ │
│                                                                            │
│     color_system = 'truecolor'                                             │
│         encoding = 'utf-8'                                                 │
│             file = <ipykernel.iostream.OutStream object at 0x7ff6d4b86070> │
│           height = 100                                                     │
│    is_alt_screen = False                                                   │
│ is_dumb_terminal = False                                                   │
│   is_interactive = False                                                   │
│       is_jupyter = True                                                    │
│      is_terminal = False                                                   │
│   legacy_windows = False                                                   │
│         no_color = False                                                   │
│          options = ConsoleOptions(                                         │
│                        size=ConsoleDimensions(width=115, height=100),      │
│                        legacy_windows=False,                               │
│                        min_width=1,                                        │
│                        max_width=115,                                      │
│                        is_terminal=False,                                  │
│                        encoding='utf-8',                                   │
│                        max_height=100,                                     │
│                        justify=None,                                       │
│                        overflow=None,                                      │
│                        no_wrap=False,                                      │
│                        highlight=None,                                     │
│                        markup=None,                                        │
│                        height=None                                         │
│                    )                                                       │
│            quiet = False                                                   │
│           record = False                                                   │
│         safe_box = True                                                    │
│             size = ConsoleDimensions(width=115, height=100)                │
│        soft_wrap = False                                                   │
│           stderr = False                                                   │
│            style = None                                                    │
│         tab_size = 8                                                       │
│            width = 115                                                     │
╰────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-color',         │
│     'COLORTERM': None,             │
│     'CLICOLOR': '1',               │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': '90838',     │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"
I'm using jupyterlab version 3.2.4, being run from RStudio Workbench on Linux with Python 3.8.14. I have ipywidgets version 8.0.4. Rich version 12.5.1.

Different ipywidgets version

It gets more interesting when I use an ipywidgets version 7.7.2 (last version before v8.0), everything else kept equal. Then I get this output: image

Different environment

When running on a standalone jupyter lab instance on a different machine I even get this behaviour: image This is run with jupyter lab version 3.5.2, ipywidgets 7.7.2, rich 12.6.0, python 3.9.12 on Windows 10. I also tried ipywidgets 8.0.4 which gives equal behaviour.

I don't know if this is all related, but I wanted to be complete. Is there any additional information I can provide that would help?

Damacustas avatar Jan 04 '23 08:01 Damacustas