prompt-toolkit / prompt-toolkit/python-prompt-toolkit

really bad flickering when there's lots of output

Open
#680 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

patch-stdout
Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

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).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the prompt_toolkit.output.vt100.Vt100_Output erase_down path and the patch_stdout interaction in the provided reproduction. Run the example with the OSX Terminal setup described, then compare rendering while output is printed continuously and completion is active. Done means the prompt, right prompt, status bar, and completion remain usable without persistent flickering.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.