예제 #1
0
파일: main.py 프로젝트: zengchunyun/mycli
 def handle_editor_command(self, cli, document):
     """
     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"<enter> to edit it in vim, then come
     back to the prompt with the edited query "select * from
     blah where q = 'abc'\e" to edit it again.
     :param cli: CommandLineInterface
     :param document: Document
     :return: Document
     """
     # FIXME: using application.pre_run_callables like this here is not the best solution.
     # It's internal api of prompt_toolkit that may change. This was added to fix
     # https://github.com/dbcli/pgcli/issues/668. We may find a better way to do it in the future.
     saved_callables = cli.application.pre_run_callables
     while special.editor_command(document.text):
         filename = special.get_filename(document.text)
         sql, message = special.open_external_editor(filename,
                                                       sql=document.text)
         if message:
             # Something went wrong. Raise an exception and bail.
             raise RuntimeError(message)
         cli.current_buffer.document = Document(sql, cursor_position=len(sql))
         cli.application.pre_run_callables = []
         document = cli.run()
         continue
     cli.application.pre_run_callables = saved_callables
     return document
예제 #2
0
파일: main.py 프로젝트: juliosueiras/mycli
 def handle_editor_command(self, cli, document):
     """
     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"<enter> to edit it in vim, then come
     back to the prompt with the edited query "select * from
     blah where q = 'abc'\e" to edit it again.
     :param cli: CommandLineInterface
     :param document: Document
     :return: Document
     """
     while special.editor_command(document.text):
         filename = special.get_filename(document.text)
         sql, message = special.open_external_editor(filename,
                                                     sql=document.text)
         if message:
             # Something went wrong. Raise an exception and bail.
             raise RuntimeError(message)
         cli.current_buffer.document = Document(sql,
                                                cursor_position=len(sql))
         document = cli.run(False)
         continue
     return document
예제 #3
0
    def handle_editor_command(self, text):
        """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"<enter> to edit it in vim, then come
        back to the prompt with the edited query "select * from
        blah where q = 'abc'\e" to edit it again.
        :param text: Document
        :return: Document

        """

        while special.editor_command(text):
            filename = special.get_filename(text)
            query = (special.get_editor_query(text) or
                     self.get_last_query())
            sql, message = special.open_external_editor(filename, sql=query)
            if message:
                # Something went wrong. Raise an exception and bail.
                raise RuntimeError(message)
            while True:
                try:
                    text = self.prompt_app.prompt(
                        default=sql,
                        vi_mode=self.key_bindings == 'vi'
                    )
                    break
                except KeyboardInterrupt:
                    sql = ""

            continue
        return text
예제 #4
0
파일: main.py 프로젝트: DaveXanderXU/mycli
 def handle_editor_command(self, cli, document):
     """
     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"<enter> to edit it in vim, then come
     back to the prompt with the edited query "select * from
     blah where q = 'abc'\e" to edit it again.
     :param cli: CommandLineInterface
     :param document: Document
     :return: Document
     """
     # FIXME: using application.pre_run_callables like this here is not the best solution.
     # It's internal api of prompt_toolkit that may change. This was added to fix
     # https://github.com/dbcli/pgcli/issues/668. We may find a better way to do it in the future.
     saved_callables = cli.application.pre_run_callables
     while special.editor_command(document.text):
         filename = special.get_filename(document.text)
         query = (special.get_editor_query(document.text) or
                  self.get_last_query())
         sql, message = special.open_external_editor(filename, sql=query)
         if message:
             # Something went wrong. Raise an exception and bail.
             raise RuntimeError(message)
         cli.current_buffer.document = Document(sql, cursor_position=len(sql))
         cli.application.pre_run_callables = []
         document = cli.run()
         continue
     cli.application.pre_run_callables = saved_callables
     return document
예제 #5
0
 def handle_editor_command(self, cli, document):
     """
     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"<enter> to edit it in vim, then come
     back to the prompt with the edited query "select * from
     blah where q = 'abc'\e" to edit it again.
     :param cli: CommandLineInterface
     :param document: Document
     :return: Document
     """
     while special.editor_command(document.text):
         filename = special.get_filename(document.text)
         sql, message = special.open_external_editor(filename, sql=document.text)
         if message:
             # Something went wrong. Raise an exception and bail.
             raise RuntimeError(message)
         cli.current_buffer.document = Document(sql, cursor_position=len(sql))
         document = cli.run(False)
         continue
     return document