prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Add example for converting from readline-based key bindings to Prompt Toolkit
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
The keybinding example shows how to do some fancy things with key bindings (CtrlT to print "hello world"), so it's clear how to execute an arbitrary callable for a given key combination (or at least, for key combinations defined in from prompt_toolkit.keys.Keys), but if I just want to customize key combinations for existing cursor functions, where would I go? For instance, my .inputrc contains:
C-f: backward-word
C-g: backward-kill-word
The prompt-toolkit alternative should be something like:
from prompt_toolkit import prompt
from prompt_toolkit.key_binding.manager import KeyBindingManager
from prompt_toolkit.keys import Keys
manager = KeyBindingManager.for_prompt()
@manager.registry.add_binding(Keys.ControlF)
def _(event):
# < Function call to move cursor backward one word>
@manager.registry.add_binding(Keys.ControlG)
def _(event):
# < Function call to kill backward one word>
I'd be happy to add something like this to the keybinding example, if someone can tell me what functions to call. Cheers!
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 examples/custom-key-binding.py and the KeyBindingManager and Keys entry points named in the issue. Find the existing cursor and kill-word functions that correspond to the two inputrc bindings, then update the example to show both conversions and verify that the documented key combinations perform the requested actions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100