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
(self, text)
| 284 | sys.exit(1) |
| 285 | |
| 286 | def handle_editor_command(self, text): |
| 287 | r""" |
| 288 | Editor command is any query that is prefixed or suffixed |
| 289 | by a '\e'. The reason for a while loop is because a user |
| 290 | might edit a query multiple times. |
| 291 | For eg: |
| 292 | "select * from \e"<enter> to edit it in vim, then come |
| 293 | back to the prompt with the edited query "select * from |
| 294 | blah where q = 'abc'\e" to edit it again. |
| 295 | :param text: Document |
| 296 | :return: Document |
| 297 | """ |
| 298 | # FIXME: using application.pre_run_callables like this here is not the best solution. |
| 299 | # It's internal api of prompt_toolkit that may change. This was added to fix #668. |
| 300 | # We may find a better way to do it in the future. |
| 301 | # pylint: disable=no-member |
| 302 | editor_command = special.editor_command(text) |
| 303 | while editor_command: |
| 304 | filename = special.get_filename(text) |
| 305 | query = (special.get_editor_query(text) or |
| 306 | self.get_last_query()) |
| 307 | sql, message = special.open_external_editor(filename, sql=query) |
| 308 | if message: |
| 309 | # Something went wrong. Raise an exception and bail. |
| 310 | raise RuntimeError(message) |
| 311 | while True: |
| 312 | try: |
| 313 | text = self.prompt_session.prompt(default=sql) |
| 314 | break |
| 315 | except KeyboardInterrupt: |
| 316 | sql = "" |
| 317 | |
| 318 | editor_command = special.editor_command(text) |
| 319 | return text |
| 320 | |
| 321 | def _execute_interactive_command(self, text): |
| 322 | """ Runs commands in the interactive CLI mode. """ |