本文整理汇总了Python中prompt_toolkit.shortcuts.prompt方法的典型用法代码示例。如果您正苦于以下问题:Python shortcuts.prompt方法的具体用法?Python shortcuts.prompt怎么用?Python shortcuts.prompt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.shortcuts
的用法示例。
在下文中一共展示了shortcuts.prompt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bootstrap_prompt
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def bootstrap_prompt(prompt_kwargs, group):
"""
Bootstrap prompt_toolkit kwargs or use user defined values.
:param prompt_kwargs: The user specified prompt kwargs.
"""
prompt_kwargs = prompt_kwargs or {}
defaults = {
"history": InMemoryHistory(),
"completer": ClickCompleter(group),
"message": u"> ",
}
for key in defaults:
default_value = defaults[key]
if key not in prompt_kwargs:
prompt_kwargs[key] = default_value
return prompt_kwargs
示例2: continue_prompt
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def continue_prompt(message=""):
"""Prompt the user to continue or not
Returns True when the user type Yes.
:param message: message to display
:type message: str
:rtype: bool
"""
answer = False
message = message + "\n'Yes' or 'No' to continue: "
while answer not in ('Yes', 'No'):
answer = prompt(message, eventloop=eventloop())
if answer == "Yes":
answer = True
break
if answer == "No":
answer = False
break
return answer
示例3: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
# We wrap it in a ThreadedCompleter, to make sure it runs in a different
# thread. That way, we don't block the UI while running the completions.
slow_completer = SlowCompleter()
# Add a bottom toolbar that display when completions are loading.
def bottom_toolbar():
return " Loading completions... " if slow_completer.loading > 0 else ""
# Display prompt.
text = prompt(
"Give some animals: ",
completer=slow_completer,
complete_in_thread=True,
complete_while_typing=True,
bottom_toolbar=bottom_toolbar,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
示例4: run
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def run(self):
""" Main entry function. """
history = InMemoryHistory()
self._load_file()
while True:
# (re)load the todo.txt file (only if it has been modified)
try:
user_input = prompt(u'topydo> ', history=history,
completer=self.completer,
complete_while_typing=False)
user_input = shlex.split(user_input)
except EOFError:
sys.exit(0)
except KeyboardInterrupt:
continue
except ValueError as verr:
error('Error: ' + str(verr))
continue
try:
(subcommand, args) = get_subcommand(user_input)
except ConfigError as ce:
error('Error: ' + str(ce) + '. Check your aliases configuration')
continue
try:
if self._execute(subcommand, args) != False:
self._post_execute()
except TypeError:
print(GENERIC_HELP)
示例5: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
""" Main entry point of the prompt interface. """
PromptApplication().run()
示例6: run
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def run(self):
buf = ""
self.logger.handle("Commands available: list | quit | check [CVE_NUMBER] | exploit [CVE_NUMBER]", None)
while True:
buf = prompt("\nDrupwn> ", history=self.history, completer=self.auto_cmds, complete_while_typing=False)
args = buf.split(" ")
try:
if args[0] == "quit":
break
self.cmds[args[0]](args)
except:
pass
示例7: interact
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def interact(connection):
clear()
connection.send("Welcome!\n")
# Ask for input.
result = await prompt(message="Say something: ", async_=True)
# Send output.
connection.send("You said: {}\n".format(result))
connection.send("Bye.\n")
示例8: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
answer = prompt("Give me some input: ", lexer=RainbowLexer())
print("You said: %s" % answer)
示例9: get_prompt
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def get_prompt():
" Tokens to be shown before the prompt. "
now = datetime.datetime.now()
return [
("bg:#008800 #ffffff", "%s:%s:%s" % (now.hour, now.minute, now.second)),
("bg:cornsilk fg:maroon", " Enter something: "),
]
示例10: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
result = prompt(get_prompt, refresh_interval=0.5)
print("You said: %s" % result)
示例11: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
text = prompt(
"Give some animals: ",
completer=animal_completer,
complete_style=CompleteStyle.MULTI_COLUMN,
)
print("You said: %s" % text)
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:9,代码来源:multi-column-autocompletion-with-meta.py
示例12: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
text = prompt(
"Give some animals: ", completer=animal_completer, complete_while_typing=True
)
print("You said: %s" % text)
示例13: main
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def main():
text = prompt(
"Give some animals: ",
completer=animal_completer,
complete_style=CompleteStyle.READLINE_LIKE,
)
print("You said: %s" % text)
示例14: prompt
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def prompt(self):
message = [
('class:pygments.os', OS_MATCHING[self.os]),
('class:pygments.colon', ':'),
('class:pygments.mode', self.mode),
('class:pygments.colon', ':'),
('class:pygments.arch', self.pexec.arch),
('class:pygments.pound', ' > ')
]
return prompt(message, style=self.prompt_style, history=self.__get_history())
示例15: irun
# 需要导入模块: from prompt_toolkit import shortcuts [as 别名]
# 或者: from prompt_toolkit.shortcuts import prompt [as 别名]
def irun(self):
while True:
try:
cmd = self.prompt()
if cmd == '':
continue
else:
if not self.handle_command(cmd):
cprint('\n<red,bold>[-]</> Invalid command.\n')
except Exception as e:
cprint('\n<red,bold>[-]</> Error occured: {}\n'.format(e))
except KeyboardInterrupt:
cprint()