rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Addressing Dashboard Freeze and Cursor Flicker Issues in Real-Time Data Applications Using Rich

Open kaidaniel82 opened this issue 2 years ago • 11 comments

Hi,

I have created a dashboard with real-time data using Rich. However, I am encountering two issues. First, the input cursor from the terminal occasionally flickers, which leads people to click on the UI, causing it to freeze until I resize the terminal window. Second, it appears that when the UI freezes due to mouse clicks, some of my backend processes, like logging to files, also start to freeze.

python == 3.11 rich==13.7.0

Running on Windows 11 and Windows Server 2022.

kaidaniel82 avatar Jan 25 '24 00:01 kaidaniel82

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Jan 25 '24 00:01 github-actions[bot]

Can you provide a MRE to reproduce the issue you're describing?

TomJGooding avatar Jan 25 '24 00:01 TomJGooding

I deleted all what is not needed ... but it shows the issue.

If I ran tis code on windows 2022 Server it freaks out...

from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.layout import Layout
from rich.text import Text
from datetime import datetime
from rich.live import Live
import time

console = Console()


def make_layout():
    layout = Layout(name="root")

    layout.split_column(
        Layout(name="header", size=3),
        Layout(name="main", size=8),
        Layout(name="footer", size=5),
    )

    layout["main"].split_row(
        Layout(name="account"),
        Layout(name="indicator"),
        Layout(name="money_management"),
        Layout(name="license"),
        Layout(name="connectivity"),
    )

    return layout


class Header:
    def __init__(self):
        pass

    def __rich__(self) -> Panel:
        market_info = f"Next Opening in {5}h {5}min"
        grid = Table.grid(expand=True)
        grid.add_column(justify="left")
        grid.add_column(justify="center", ratio=1)
        grid.add_column(justify="right")
        grid.add_row(
            Text("H | Version 1.1"),
            Text(market_info, style="red"),
            Text(datetime.today().strftime("%Y-%m-%d %H:%M:%S")),
        )
        return Panel(grid, style="bold black on #003366")


layout = make_layout()
layout["header"].update(Header())

console.clear()
with Live(layout, refresh_per_second=20, screen=True):
    while True:
        time.sleep(1)

kaidaniel82 avatar Jan 25 '24 01:01 kaidaniel82

https://github.com/Textualize/rich/assets/127942818/08c7e935-b163-489c-8741-6cf282810b3c

kaidaniel82 avatar Jan 25 '24 01:01 kaidaniel82

Here you see the freeze of UI

https://github.com/Textualize/rich/assets/127942818/31ad1218-95fa-4a55-9475-88f641667294

kaidaniel82 avatar Jan 25 '24 01:01 kaidaniel82

I get the same pause effect with a Windows console window if I run this program, no Rich involved at all:

from time import sleep

for n in range(10_000):
    print(str(n))
    sleep(1)

This seems to be standard behaviour for Windows console and nothing to do with Rich.

I'm no Windows person, but a quick search online suggests this is related to something called "Quick Edit Mode", perhaps?

davep avatar Jan 25 '24 09:01 davep

Hi, by "Quick Edit Mode" deactivate makes the freeze issue solved but it is still massive flickering. I also still see the Cursor flickering.

thanks a lot. Screenshot 2024-01-25 at 11 31 00

kaidaniel82 avatar Jan 25 '24 10:01 kaidaniel82

You may want to try the new Windows Terminal. The legacy terminal has a lot of issues. You also may want to consider the Textual for things like this.

willmcgugan avatar Jan 25 '24 11:01 willmcgugan

Hi, its exactly the same in powershell terminal. Could you pls advice how to realize a Dashboard easiliy in Textual?

best

kaidaniel82 avatar Jan 25 '24 11:01 kaidaniel82

Will is suggesting that you look at Windows Terminal.

davep avatar Jan 25 '24 11:01 davep

Thanks, i will give it a try. However i can not guarantee that this new styled terminal is installed on the clients machine. I will update my findings here...

looks like there is a github repository enabling download https://github.com/microsoft/terminal

kaidaniel82 avatar Jan 25 '24 11:01 kaidaniel82