prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 718 forks source link

really bad flickering when there's lots of output #680

Open vlovich opened 5 years ago

vlovich commented 5 years ago

The prompt, right prompt & status bar (i.e. completion) are really bad (unusable) if there's a lot of output. Attached a repro case. Flickering of the completion can be improved by replacing erase to bottom with erase to end. The prompt still flickers at all times even with this (just uncomment out Vt100_Output.erase_down = flicker_fix to test it out). The rendering probably needs to better understand where the prompt cursor is & erase the non-prompt parts.

from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop
from prompt_toolkit.patch_stdout import patch_stdout
from prompt_toolkit.shortcuts import CompleteStyle
from prompt_toolkit.shortcuts.prompt import prompt
from threading import Thread
from prompt_toolkit.output.vt100 import Vt100_Output

import time

def flicker_fix(self):
  self.write_raw('\x1b[K')

# Vt100_Output.erase_down = flicker_fix

def spam_print():
  while True:
    print("This is spam")
    time.sleep(0.01)

Thread(target=spam_print, daemon=True).start()

while True:
  with patch_stdout():
    prompt("> ", rprompt="test", complete_style=CompleteStyle.MULTI_COLUMN,
           completer=WordCompleter(list(chr(c) * 20 for c in range(ord("a"), ord("z")))))

Tested with OSX Terminal app (10.13.5)

Somewhat related to #547 although a different manifestation & a more serious consequence (especially when combined with #681).

jonathanslenders commented 5 years ago

See my remark here: https://github.com/jonathanslenders/python-prompt-toolkit/issues/682 I think that bundling outputs in patch_stdout with a timer should also solve this issue.

vlovich commented 5 years ago

Interesting idea. I'll try it out.

vlovich commented 5 years ago

Tried the timer, didn't seem to help.