spyder-ide / spyder-kernels

Jupyter Kernels for the Spyder console
MIT License
38 stars 39 forks source link

Strange behaviors when using rich package in dealing with multiple line representation in Spider console. #494

Open MekJohn opened 3 months ago

MekJohn commented 3 months ago

Using rich python package all going fine if you use only one line on live console display, but something weird come up when multiple line display are required with other complex objects like progress bars or tables ...

One line progress is ok in the spider console. See the following code took from rich documentation.

import time
from rich.progress import track

for i in track(range(20), description="Processing..."):
    time.sleep(1) 

image

The weird things happen when you have to use multiple lines representation (also this example is taken from rich documentation).

import time

from rich.progress import Progress

with Progress() as progress:

    task1 = progress.add_task("[red]Downloading...", total=1000)
    task2 = progress.add_task("[green]Processing...", total=1000)
    task3 = progress.add_task("[cyan]Cooking...", total=1000)

    while not progress.finished:
        progress.update(task1, advance=0.5)
        progress.update(task2, advance=0.3)
        progress.update(task3, advance=0.9)
        time.sleep(0.02)

In Spider console this last code block displays a result where only the last line is kept updated in place, printing others in multiple lines for each updates. See below.

image

In win console obviously there aren't any problems about that. All the three lines are kept updated in place.

image

Is there a way to solve it?


Win 11 Python 3.11 Spyder IDE 5.4.4 spyder-kernels 2.4.2 PyQt5 5.15.10 PyQt5-Qt5 5.15.2 PyQt5-sip 12.13.0_

dalthviz commented 3 days ago

Hi there @MekJohn thank you for the feedback! I think this something that needs to be solved over QtConsole. In fact, we are aiming to improve the behavior over https://github.com/jupyter/qtconsole/pull/616. However, seems like we need further work over there. Running your example code with the changes over there I see the following:

image