Set up the prompt_toolkit keyboard shortcuts for IPython. Parameters ---------- shell: InteractiveShell The current IPython shell Instance skip: List[Binding] Bindings to skip. Returns ------- KeyBindings the keybinding instance for prompt toolki
(shell, skip=None)
| 326 | |
| 327 | |
| 328 | def create_ipython_shortcuts(shell, skip=None) -> KeyBindings: |
| 329 | """Set up the prompt_toolkit keyboard shortcuts for IPython. |
| 330 | |
| 331 | Parameters |
| 332 | ---------- |
| 333 | shell: InteractiveShell |
| 334 | The current IPython shell Instance |
| 335 | skip: List[Binding] |
| 336 | Bindings to skip. |
| 337 | |
| 338 | Returns |
| 339 | ------- |
| 340 | KeyBindings |
| 341 | the keybinding instance for prompt toolkit. |
| 342 | |
| 343 | """ |
| 344 | kb = KeyBindings() |
| 345 | skip = skip or [] |
| 346 | for binding in KEY_BINDINGS: |
| 347 | skip_this_one = False |
| 348 | for to_skip in skip: |
| 349 | if ( |
| 350 | to_skip.command == binding.command |
| 351 | and to_skip.filter == binding.filter |
| 352 | and to_skip.keys == binding.keys |
| 353 | ): |
| 354 | skip_this_one = True |
| 355 | break |
| 356 | if skip_this_one: |
| 357 | continue |
| 358 | add_binding(kb, binding) |
| 359 | |
| 360 | def get_input_mode(self): |
| 361 | app = get_app() |
| 362 | app.ttimeoutlen = shell.ttimeoutlen |
| 363 | app.timeoutlen = shell.timeoutlen |
| 364 | |
| 365 | return self._input_mode |
| 366 | |
| 367 | def set_input_mode(self, mode): |
| 368 | shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6) |
| 369 | cursor = "\x1b[{} q".format(shape) |
| 370 | |
| 371 | sys.stdout.write(cursor) |
| 372 | sys.stdout.flush() |
| 373 | |
| 374 | self._input_mode = mode |
| 375 | |
| 376 | if shell.editing_mode == "vi" and shell.modal_cursor: |
| 377 | ViState._input_mode = InputMode.INSERT # type: ignore |
| 378 | ViState.input_mode = property(get_input_mode, set_input_mode) # type: ignore |
| 379 | |
| 380 | return kb |
| 381 | |
| 382 | |
| 383 | def reformat_and_execute(event): |
searching dependent graphs…