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,
)
| 49 | |
| 50 | |
| 51 | def 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 | |
| 92 | def handle_prettify_binding( |
no test coverage detected