本文整理汇总了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()
示例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)
示例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())
示例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
示例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
示例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)