prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Problems understanding PipeInput
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
Hi. I'm studying your library since a while, but didn't find a proper way of fixing my issue.
In brief: I have a customized app, eventloop, and cli. I want the user to pass a custom input (let's say a PipeInput) to the cli.
I send 4 \n separated lines on the PipeInput, but it looks to me the prompt doesn't process three commands.
A minimal script is:
import prompt_toolkit as pt
def my_prompt(prompt_in):
"""
Inspired by prompt_toolkit.shortcuts.prompt()
"""
line = None
try:
app = pt.shortcuts.create_prompt_application(
erase_when_done=True,
)
el = pt.shortcuts.create_eventloop()
cli = pt.interface.CommandLineInterface(
application=app,
input=prompt_in,
eventloop=el,
output=pt.shortcuts.create_output(true_color=False)
)
patch_context = pt.utils.DummyContext()
with patch_context:
doc = cli.run(reset_current_buffer=True)
if doc:
line = doc.text.strip()
except EOFError:
line = None
return line
# setup the input
prompt_in = pt.input.PipeInput()
prompt_in.send("foo\nfie\nfoo\nfie\n")
# start the interpretation loop
while True:
try:
line = my_prompt(prompt_in)
if line is None:
break
print "[%s]" % line
except KeyboardInterrupt:
print "Goodbye"
break
except Exception, e:
print "Error: %s" % e
break
The output is:
user@host:wd$ python example.py
foo
[foo]
^[[23;1R^[[23;9R
I can't understand what those strange sequences of characters mean, and how to debug this problem.
Hope you can shed some light :) Thanks
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 minimal script with PipeInput and trace create_prompt_application, create_eventloop, and CommandLineInterface.run. Check how the input is consumed across repeated prompts and how terminal response sequences are handled. Done means all four newline-separated inputs are processed as separate lines without emitting the unexpected escape sequences.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100