MCPcopy Create free account
hub / github.com/dbcli/mycli / handle_editor_command

Function handle_editor_command

mycli/packages/key_binding_utils.py:51–89  ·  view source on GitHub ↗

r"""Editor command is any query that is prefixed or suffixed by a '\e'. The reason for a while loop is because a user might edit a query multiple times. For eg: "select * from \e" to edit it in vim, then come back to the prompt with the edited query "select * from blah wh

(
    mycli: 'MyCli',
    text: str,
    inputhook: Callable | None,
    loaded_message_fn: Callable,
)

Source from the content-addressed store, hash-verified

49
50
51def handle_editor_command(
52 mycli: 'MyCli',
53 text: str,
54 inputhook: Callable | None,
55 loaded_message_fn: Callable,
56) -> str:
57 r"""Editor command is any query that is prefixed or suffixed by a '\e'.
58 The reason for a while loop is because a user might edit a query
59 multiple times. For eg:
60
61 "select * from \e"<enter> to edit it in vim, then come
62 back to the prompt with the edited query "select * from
63 blah where q = 'abc'\e" to edit it again.
64 :param text: Document
65 :return: Document
66
67 """
68
69 while special.editor_command(text):
70 filename = special.get_filename(text)
71 query = special.get_editor_query(text) or mycli.get_last_query()
72 sql, message = special.open_external_editor(filename=filename, sql=query)
73 if message:
74 # Something went wrong. Raise an exception and bail.
75 raise RuntimeError(message)
76 while True:
77 try:
78 assert isinstance(mycli.prompt_session, PromptSession)
79 text = mycli.prompt_session.prompt(
80 default=sql,
81 inputhook=inputhook,
82 message=loaded_message_fn,
83 )
84 break
85 except KeyboardInterrupt:
86 sql = ""
87
88 continue
89 return text
90
91
92def handle_prettify_binding(

Callers 1

_one_iterationFunction · 0.90

Calls 2

get_last_queryMethod · 0.45
promptMethod · 0.45

Tested by

no test coverage detected