prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Typeahead doesn't work very well with multiple lines
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
This surely must be an issue you know about, but I couldn't find any issues for it. Typeahead support in prompt toolkit is very buggy. It's basically unusable, because it can't be relied on.
It seems to eat anything after the first newline. It also sometimes eats part of the typed text, but I haven't yet found a good way to reproduce that.
Consider a simple prompt
from prompt_toolkit.shortcuts import prompt
import time
while True:
time.sleep(3)
a = prompt('> ')
print(a)
I run python test.py and then type
1
2
3
4
I expect each to enter prompt as it appears. What happens instead is
1
2
3
3
> 1
1
>
So it eats all but the first. If I do it again in the same session, I get
> 1
1
2
3
4
> 2
2
>
again, it eats all the typeahead up to the first newline.
I tested this in 2.0, as I know there are a lot of changes there, and it's even worse!
1
2
3
4
> 1234
None
> 1
1
2
3
4
> 234
None
So instead of eating the newlines, it erased them (also, prompt no longer returns the input in 2.0?).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided test.py reproducer using prompt_toolkit.shortcuts.prompt, then trace how typeahead input is handled around the prompt entry point. Verify behavior with the multiline sequence 1, 2, 3, 4. Done means each line is delivered to a successive prompt without text or newlines being lost, and prompt returns the entered input as expected.
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
- 30/100