當前位置: 首頁>>代碼示例>>Python>>正文


Python shortcuts.create_eventloop方法代碼示例

本文整理匯總了Python中prompt_toolkit.shortcuts.create_eventloop方法的典型用法代碼示例。如果您正苦於以下問題:Python shortcuts.create_eventloop方法的具體用法?Python shortcuts.create_eventloop怎麽用?Python shortcuts.create_eventloop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在prompt_toolkit.shortcuts的用法示例。


在下文中一共展示了shortcuts.create_eventloop方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from prompt_toolkit import shortcuts [as 別名]
# 或者: from prompt_toolkit.shortcuts import create_eventloop [as 別名]
def __init__(self, parser, engine, options=None):
        self.parser = parser
        self.engine = engine
        self.options = options if options is not None else {}
        util.ensure_data_dir_exists()
        application = create_prompt_application(
            message='> ',
            lexer=PygmentsLexer(SqlLexer),
            history=FileHistory(os.path.expanduser('~/.aq/history')),
            completer=AqCompleter(schemas=engine.available_schemas, tables=engine.available_tables),
            auto_suggest=AutoSuggestFromHistory(),
            validator=QueryValidator(parser),
            on_abort=AbortAction.RETRY,
        )
        loop = create_eventloop()
        self.cli = CommandLineInterface(application=application, eventloop=loop)
        self.patch_context = self.cli.patch_stdout_context() 
開發者ID:lebinh,項目名稱:aq,代碼行數:19,代碼來源:prompt.py

示例2: eventloop

# 需要導入模塊: from prompt_toolkit import shortcuts [as 別名]
# 或者: from prompt_toolkit.shortcuts import create_eventloop [as 別名]
def eventloop():
    # Allow to keep gevent greenlets running
    # while waiting for some input on the cli
    def inputhook(context):
        while not context.input_is_ready():
            gevent.sleep(0.1)

    return create_eventloop(inputhook=inputhook) 
開發者ID:eonpatapon,項目名稱:contrail-api-cli,代碼行數:10,代碼來源:utils.py

示例3: create_interface

# 需要導入模塊: from prompt_toolkit import shortcuts [as 別名]
# 或者: from prompt_toolkit.shortcuts import create_eventloop [as 別名]
def create_interface(self):
        """ instantiates the intereface """
        return CommandLineInterface(
            application=self.create_application(),
            eventloop=create_eventloop()) 
開發者ID:Azure,項目名稱:azure-cli-shell,代碼行數:7,代碼來源:app.py

示例4: example_repl

# 需要導入模塊: from prompt_toolkit import shortcuts [as 別名]
# 或者: from prompt_toolkit.shortcuts import create_eventloop [as 別名]
def example_repl(self, text, example, start_index, continue_flag):
        """ REPL for interactive tutorials """

        if start_index:
            start_index = start_index + 1
            cmd = ' '.join(text.split()[:start_index])
            example_cli = CommandLineInterface(
                application=self.create_application(
                    full_layout=False),
                eventloop=create_eventloop())
            example_cli.buffers['example_line'].reset(
                initial_document=Document(u'{}\n'.format(
                    add_random_new_lines(example)))
            )
            while start_index < len(text.split()):
                if self.default_command:
                    cmd = cmd.replace(self.default_command + ' ', '')
                example_cli.buffers[DEFAULT_BUFFER].reset(
                    initial_document=Document(
                        u'{}'.format(cmd),
                        cursor_position=len(cmd)))
                example_cli.request_redraw()
                answer = example_cli.run()
                if not answer:
                    return "", True
                answer = answer.text
                if answer.strip('\n') == cmd.strip('\n'):
                    continue
                else:
                    if len(answer.split()) > 1:
                        start_index += 1
                        cmd += " " + answer.split()[-1] + " " +\
                               u' '.join(text.split()[start_index:start_index + 1])
            example_cli.exit()
            del example_cli
        else:
            cmd = text

        return cmd, continue_flag

    # pylint: disable=too-many-branches 
開發者ID:Azure,項目名稱:azure-cli-shell,代碼行數:43,代碼來源:app.py

示例5: create_cli_interface

# 需要導入模塊: from prompt_toolkit import shortcuts [as 別名]
# 或者: from prompt_toolkit.shortcuts import create_eventloop [as 別名]
def create_cli_interface(self, display_completions_in_columns):
        # A CommandLineInterface from prompt_toolkit
        # accepts two things: an application and an
        # event loop.
        loop = create_eventloop()
        app = self.create_application(self.completer,
                                      self.file_history,
                                      display_completions_in_columns)
        cli = CommandLineInterface(application=app, eventloop=loop,
                                   input=self._input, output=self._output)
        return cli 
開發者ID:awslabs,項目名稱:aws-shell,代碼行數:13,代碼來源:app.py

示例6: run

# 需要導入模塊: from prompt_toolkit import shortcuts [as 別名]
# 或者: from prompt_toolkit.shortcuts import create_eventloop [as 別名]
def run(self):
    labels = self.neo4j.get_labels()
    relationship_types = self.neo4j.get_relationship_types()
    properties = self.neo4j.get_property_keys()

    if self.filename:
      with io.open(self.filename, "r") as f:
        queries = split_queries_on_semicolons(f.read())

        for query in queries:
          print("> " + query)
          self.handle_query(query)
          print()

        return

    click.secho(" ______     __  __     ______     __         __    ", fg="red")
    click.secho("/\  ___\   /\ \_\ \   /\  ___\   /\ \       /\ \   ", fg="yellow")
    click.secho("\ \ \____  \ \____ \  \ \ \____  \ \ \____  \ \ \  ", fg="green")
    click.secho(" \ \_____\  \/\_____\  \ \_____\  \ \_____\  \ \_\ ", fg="blue")
    click.secho("  \/_____/   \/_____/   \/_____/   \/_____/   \/_/ ", fg="magenta")

    print("Cycli version: {}".format(__version__))
    print("Neo4j version: {}".format(".".join(map(str, self.neo4j.neo4j_version))))
    print("Bug reports: https://github.com/nicolewhite/cycli/issues\n")

    completer = CypherCompleter(labels, relationship_types, properties)

    layout = create_prompt_layout(
      lexer=CypherLexer,
      get_prompt_tokens=get_tokens,
      reserve_space_for_menu=8,
    )

    buff = CypherBuffer(
      accept_action=AcceptAction.RETURN_DOCUMENT,
      history=FileHistory(filename=os.path.expanduser('~/.cycli_history')),
      completer=completer,
      complete_while_typing=True,
    )

    application = Application(
      style=PygmentsStyle(CypherStyle),
      buffer=buff,
      layout=layout,
      on_exit=AbortAction.RAISE_EXCEPTION,
      key_bindings_registry=CypherBinder.registry
    )

    cli = CommandLineInterface(application=application, eventloop=create_eventloop())

    try:
      while True:
        document = cli.run()
        query = document.text
        self.handle_query(query)
    except UserWantsOut:
      print("Goodbye!")
    except Exception as e:
      print(e) 
開發者ID:nicolewhite,項目名稱:cycli,代碼行數:62,代碼來源:main.py


注:本文中的prompt_toolkit.shortcuts.create_eventloop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。