prompt-toolkit / prompt-toolkit/python-prompt-toolkit
prompt toolkit accept when enter pressed
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
I am using prompt toolkit for my CLI. the issue I am facing is when having multiple options and if the user presses "enter" it executes the command. I want different behavior for "enter". when the user presses "enter" it should select the option and if the user presses "enter" again then it should execute the command I have added the below code
kb = key_binding.KeyBindings()
@kb.add('enter')
def _enter_key(event) -> None:
buff = event.current_buffer
if not buff.complete_state:
named_commands.accept_line(event)
else:
named_commands.complete(event)
session = PromptSession(message=cli_command, style=style if colors_enabled else None, complete_while_typing=True)
text = session.prompt(completer=multithread_completer, default=document, pre_run=session.default_buffer.start_completion, key_bindings=kb)
but it acts similar to "tab" meaning if the options are "a ab abc" and the user chooses "a" and press "enter" it still shows the three options, I want it to choose only "a". please let me know what am I doing wrong
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 KeyBindings, named_commands.complete, and PromptSession usage shown in the issue, then trace how completion state handles Enter versus Tab. Confirm the intended behavior with options such as "a", "ab", and "abc": the first Enter should select only "a", while the second should execute the command.
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