prompt-toolkit / prompt-toolkit/python-prompt-toolkit
rendering trouble... [including testcase to reproduce the issue]
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
@jonathanslenders prompt-toolkit gave me some headaches during testing (https://github.com/jonathanslenders/python-prompt-toolkit/issues/598, https://github.com/jonathanslenders/python-prompt-toolkit/issues/597) so I analysed and found out that indeed it is doing things differently (at least different to bash).
Both testcases use a virtual screen so we can "see" what is going on.
on most recent Arch Linux I get the following results with prompt-toolkit 2:
--------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------
Give me some input: #
Give me some input: my input... #
#
...
simple_prompt.bash:
#!/bin/bash
printf 'Give me some input: '
read -r opt
simple_prompt.py:
from prompt_toolkit import prompt
answer = prompt('Give me some input: ')
testcases:
# -*- coding: utf-8 -*-
from pexpect import ANSI
import pexpect
from prompt_toolkit import Prompt
from prompt_toolkit.input.vt100 import PipeInput
from prompt_toolkit.output import DummyOutput
def test_simple_app_bash():
child = pexpect.spawn('./tests/simple_prompt.bash')
term = ANSI.ANSI()
child.logfile_read = term
child.expect('Give me some input: ')
#child.echo = 1
child.sendline ('my input...' + '\x0a')
child.expect ('my input...')
# get some output
for c in term.w:
print(u''.join(c) + '#')
assert ''.join(term.w[0]).strip() == 'Give me some input: my input...'
assert ''.join(term.w[1]).strip() == ''
def test_simple_app_python():
child = pexpect.spawn('python tests/simple_prompt.py')
term = ANSI.ANSI()
child.logfile_read = term
child.expect('Give me some input: ')
#child.echo = 1
child.sendline ('my input...' + '\x0a')
child.expect ('my input...')
for c in term.w:
print(u''.join(c) + '#')
assert False
assert ''.join(term.w[0]).strip() == 'Give me some input: my input...'
assert ''.join(term.w[1]).strip() == ''
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 by running the two reproductions in the issue: tests/simple_prompt.bash and tests/simple_prompt.py, using the provided pexpect ANSI virtual-screen setup. Compare the captured rows for the bash and Python prompts, then inspect the prompt-toolkit input and output paths involved in the Python case. Done means the Python testcase produces the expected prompt and input rows instead of the current rendering output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100