MCPcopy
hub / github.com/prompt-toolkit/ptpython / get_inputmode_fragments

Function get_inputmode_fragments

src/ptpython/layout.py:415–473  ·  view source on GitHub ↗

Return current input mode as a list of (token, text) tuples for use in a toolbar.

(python_input: PythonInput)

Source from the content-addressed store, hash-verified

413
414
415def get_inputmode_fragments(python_input: PythonInput) -> StyleAndTextTuples:
416 """
417 Return current input mode as a list of (token, text) tuples for use in a
418 toolbar.
419 """
420 app = get_app()
421
422 @if_mousedown
423 def toggle_vi_mode(mouse_event: MouseEvent) -> None:
424 python_input.vi_mode = not python_input.vi_mode
425
426 token = "class:status-toolbar"
427 input_mode_t = "class:status-toolbar.input-mode"
428
429 mode = app.vi_state.input_mode
430 result: StyleAndTextTuples = []
431 append = result.append
432
433 if python_input.title:
434 result.extend(to_formatted_text(python_input.title))
435
436 append((input_mode_t, "[F4] ", toggle_vi_mode))
437
438 # InputMode
439 if python_input.vi_mode:
440 recording_register = app.vi_state.recording_register
441 if recording_register:
442 append((token, " "))
443 append((token + " class:record", f"RECORD({recording_register})"))
444 append((token, " - "))
445
446 if app.current_buffer.selection_state is not None:
447 if app.current_buffer.selection_state.type == SelectionType.LINES:
448 append((input_mode_t, "Vi (VISUAL LINE)", toggle_vi_mode))
449 elif app.current_buffer.selection_state.type == SelectionType.CHARACTERS:
450 append((input_mode_t, "Vi (VISUAL)", toggle_vi_mode))
451 append((token, " "))
452 elif app.current_buffer.selection_state.type == SelectionType.BLOCK:
453 append((input_mode_t, "Vi (VISUAL BLOCK)", toggle_vi_mode))
454 append((token, " "))
455 elif mode in (InputMode.INSERT, "vi-insert-multiple"):
456 append((input_mode_t, "Vi (INSERT)", toggle_vi_mode))
457 append((token, " "))
458 elif mode == InputMode.NAVIGATION:
459 append((input_mode_t, "Vi (NAV)", toggle_vi_mode))
460 append((token, " "))
461 elif mode == InputMode.REPLACE:
462 append((input_mode_t, "Vi (REPLACE)", toggle_vi_mode))
463 append((token, " "))
464 else:
465 if app.emacs_state.is_recording:
466 append((token, " "))
467 append((token + " class:record", "RECORD"))
468 append((token, " - "))
469
470 append((input_mode_t, "Emacs", toggle_vi_mode))
471 append((token, " "))
472

Callers 2

get_text_fragmentsFunction · 0.85

Calls 1

appendFunction · 0.85

Tested by

no test coverage detected