mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
update tutorial_ptk.rst
This commit is contained in:
parent
d76d9b2b5e
commit
d2484c419f
1 changed files with 9 additions and 2 deletions
|
@ -72,13 +72,17 @@ Custom keyload function
|
|||
|
||||
We need our additional keybindings to load after the shell is initialized, so we
|
||||
define a function that contains all of the custom keybindings and decorate it
|
||||
with the appropriate event, in this case ``on_ptk_create``.
|
||||
with the appropriate event, in this case ``on_ptk_create``. Please note that
|
||||
the method of ``handler`` differs depending on the version of ``prompt_toolkit``.
|
||||
|
||||
We'll start with a toy example that just inserts the text "hi" into the current line of the prompt::
|
||||
|
||||
@events.on_ptk_create
|
||||
def custom_keybindings(bindings, **kw):
|
||||
handler = bindings.registry.add_binding
|
||||
# prompt_toolkit 1.x
|
||||
# handler = bindings.registry.add_binding
|
||||
# prompt_toolkit 2.x
|
||||
handler = bindings.add
|
||||
|
||||
@handler(Keys.ControlW)
|
||||
def say_hi(event):
|
||||
|
@ -87,6 +91,9 @@ We'll start with a toy example that just inserts the text "hi" into the current
|
|||
Put that in your `xonshrc <xonshrc.html>`_, restart xonsh and then see if
|
||||
pressing ``Ctrl-w`` does anything (it should!)
|
||||
|
||||
.. note:: From prompt_toolkit 2.x it is also possible to write ``Keys.ControlW`` like ``c-w``.
|
||||
|
||||
|
||||
What commands can keybindings run?
|
||||
==================================
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue