Skip to content

Commit

Permalink
Add <esc><ctrl-j> to toggle edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Nov 11, 2024
1 parent f8c0105 commit 267687c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions trepan/inout/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
else:
from trepan.inout.prompt_bindkeys import bindings, read_inputrc, read_init_file

USER_INPUTRC = os.environ.get(
"TREPAN3K_INPUTRC", default_configfile("inputrc")
)
USER_INPUTRC = os.environ.get("TREPAN3K_INPUTRC", default_configfile("inputrc"))

read_inputrc(read_init_file, use_unicode=False)
if osp.isfile(USER_INPUTRC):
Expand All @@ -56,17 +54,26 @@ class DebuggerUserInput(Mbase.DebuggerInputBase):

def __init__(self, inp=None, opts=dict()):

self.edit_mode = opts.get("edit_mode", "emacs")
if opts.get("readline") == "prompt_toolkit":

edit_mode = opts.get("edit_mode", "vi")
prompt_editing_mode = (
EditingMode.EMACS if self.edit_mode == "emacs" else EditingMode.VI
EditingMode.EMACS if edit_mode == "emacs" else EditingMode.VI
)
self.session = PromptSession(
editing_mode=prompt_editing_mode,
enable_history_search=True,
history=FileHistory(opts.get("histfile")),
key_bindings=bindings,
)

@bindings.add("escape", "c-j")
def toggle_editmode(_):
self.session.editing_mode = (
EditingMode.VI if edit_mode == "emacs" else EditingMode.EMACS
)
print(f"\nedit mode is now {self.session.editing_mode}")

self.input = self.session.input
self.line_edit = True
self.closed = False
Expand Down
2 changes: 1 addition & 1 deletion trepan/inout/prompt_bindkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@


import pathlib
import re
from prompt_toolkit.key_binding import KeyBindings
from typing import Callable

bindings = KeyBindings()


def read_inputrc(read_init_file_fn: Callable, use_unicode: bool) -> None:
"""
Read GNU Readline style inputrc for prompt_toolkit
Expand Down

0 comments on commit 267687c

Please sign in to comment.