Closed betapro closed 6 months ago
Control-d only works if there is no input present in the input field.
Given that a default value was given, the default first needs to be erased using backspaces, and then control-d works.
For different behavior, add this key binding:
@kb.add('c-d')
def quit(event):
event.app.exit(exception=EOFError)
Hi Jonathan
Many thanks for your quick reply, which is much appreciated.
Using backspaces until the field is empty enables Ctrl+D to work exactly as you stated. However, would it be feasible (from your perspective) to change prompt_toolkit so that Ctrl+D works without having to backspace? If not, that's okay. I'd just like to know.
Anyway, I played around with your provided key binding:
@kb.add('c-d') def quit(event): event.app.exit(exception=EOFError)
and it worked like a charm, allowing except EOFError
to catch Ctrl+D without having to backspace at all.
Thanks so much!
Mike
@betapro,
Good to hear it works! The current default behavior won't be changing. The reason is that ctrl-d has a second meaning, which is "delete the character after the cursor". So, depending on whether or not there is text present, the behavior changes. This is identical to Gnu Readline on Bash.
I'm currently working on a Python 3.11.5 script on Linux Mint 21.2 that utilizes the _prompttoolkit library (3.0.43) to create a simple command-line interface for updating information about a person. However, I've encountered an issue where the script does not respond to Ctrl+D as expected, but does respond to Ctrl+C.
When Ctrl+D is pressed, the interrupt signal is not caught by EOFError. Visually, nothing appears to happen at all in the terminal or console window, and the user is able to carry on entering data without interruption.