holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.59k stars 116 forks source link

BUG: TUI animations do not work (i.e. progress bar & spinners from Rich library) #537

Open Emasoft opened 1 year ago

Emasoft commented 1 year ago

TUI animations do not work (i.e. progress bar & spinners from Rich library). They stand still and then update only after CTRL-C.

IMG_0628

holzschu commented 1 year ago

This is interesting. First, looking at python -m rich.progress, progress bars seem to be working (with some quirks).

Looking at the code of live_progress.py, the main problem is the sleep(0.1) part. If I comment this line, the progress bars appear to be working.

Emasoft commented 1 year ago

This means that the sleep command stops all the threads in a-shell before the display is updated? Maybe the display updates is too slow? I've encountered a similar problem when using the console print and exiting before flushing the buffer. By default, the python function print() prints to sys.stdout. Maybe the stdout and stderr streams buffer in a-shell is too slow or too big?

holzschu commented 1 year ago

This means that the sleep command stops all the threads in a-shell before the display is updated?

Yes, I think that's exactly what is happening. sleep works on the entire process, and because it's iOS everything shares the same process. I haven't found a way to sleep a thread while the other threads keep going.

Emasoft commented 1 year ago

A temporary solution would be to make a-Shell force the Python interpreter to always flush the buffer before executing the next command (in this case sleep), so the display will be updated before everything freezes. This can be done adding this environmental setting:

apply this to every python process in your environment with PYTHONUNBUFFERED=TRUE
holzschu commented 1 year ago

I tried (you can try it too) and it doesn't change anything. I don't think the issue is with the display.

Iamrodos commented 1 year ago

I have the same problem with rich and spinners. Normal rich text display (colors, tables etc) works fine.

For example, this normally works to display a spinner whilst data is being pulled from a remote source.

with Status("Loading data ...", spinner_style="bold default"):
        my_data = load_data()

There are no occurrences of sleep within the code. In a-shell I just get a blank line instead of the spinner followed by the text.

I did think it was a threading issue as I believe Rich uses threads to update spinners and progress bars whilst your code executes. However, I ran a simple test of threading and it appears to work ok.

Emasoft commented 1 year ago

@Iamrodos :

In a-shell I just get a blank line instead of the spinner followed by the text.

Same here. This is a pretty serious issue, since it makes Rich and Textual unusable in most scenarios.