prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Better way to send input to a prompt programatically
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
I've been using a queue, as described at https://github.com/jonathanslenders/python-prompt-toolkit/issues/519#issuecomment-318978114, to make it so that I can send text to a prompt programatically. For instance, I have a -c startup flag that allows to run a command as the first prompt. I also use this in the bracketed paste handler, as described in that issue.
The way I've done this is to pass items in the command queue through a PipeInput and use that as the input to the cli when there is a queue (and a normal input=None otherwise).
However, I'm not a fan of this approach, because it means that I have to manipulate the input command so that it gets accepted by the cli, for instance, by appending a key code that maps to accept_line.
I would much rather just set the prompt text to the command manually, and have it accept immediately. Is there a way to do this? I basically want to cli.current_buffer.insert_text(command) then have cli.run() bypass the eventloop and do a quick exit.
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 reading the linked discussion and tracing how PipeInput, cli.current_buffer.insert_text(command), and cli.run() interact with the event loop. Determine whether the existing CLI entry points support inserting a command and accepting it immediately; done means a documented, tested way to run the command without manipulating input with an accept_line key code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100