1

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

Hamada Ibrahim
  • 103
  • 1
  • 1
  • 6

0 Answers0