update tutorial_ptk.rst

This commit is contained in:
@vaaaaanquish 2018-07-29 22:50:12 +09:00
parent d76d9b2b5e
commit d2484c419f

View file

@ -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?
==================================