MCPcopy Index your code
hub / github.com/prompt-toolkit/ptpython / load_python_bindings

Function load_python_bindings

src/ptpython/key_bindings.py:54–222  ·  view source on GitHub ↗

Custom key bindings.

(python_input: PythonInput)

Source from the content-addressed store, hash-verified

52
53
54def load_python_bindings(python_input: PythonInput) -> KeyBindings:
55 """
56 Custom key bindings.
57 """
58 bindings = KeyBindings()
59
60 sidebar_visible = Condition(lambda: python_input.show_sidebar)
61 handle = bindings.add
62
63 @handle("c-l")
64 def _(event: E) -> None:
65 """
66 Clear whole screen and render again -- also when the sidebar is visible.
67 """
68 event.app.renderer.clear()
69
70 @handle("c-z")
71 def _(event: E) -> None:
72 """
73 Suspend.
74 """
75 if python_input.enable_system_bindings:
76 event.app.suspend_to_background()
77
78 # Delete word before cursor, but use all Python symbols as separators
79 # (WORD=False).
80 handle("c-w")(get_by_name("backward-kill-word"))
81
82 @handle("f2")
83 def _(event: E) -> None:
84 """
85 Show/hide sidebar.
86 """
87 python_input.show_sidebar = not python_input.show_sidebar
88 if python_input.show_sidebar:
89 event.app.layout.focus(python_input.ptpython_layout.sidebar)
90 else:
91 event.app.layout.focus_last()
92
93 @handle("f3")
94 def _(event: E) -> None:
95 """
96 Select from the history.
97 """
98 python_input.enter_history()
99
100 @handle("f4")
101 def _(event: E) -> None:
102 """
103 Toggle between Vi and Emacs mode.
104 """
105 python_input.vi_mode = not python_input.vi_mode
106
107 @handle("f6")
108 def _(event: E) -> None:
109 """
110 Enable/Disable paste mode.
111 """

Callers 1

_create_applicationMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected