本文整理汇总了Python中prompt_toolkit.completion.WordCompleter方法的典型用法代码示例。如果您正苦于以下问题:Python completion.WordCompleter方法的具体用法?Python completion.WordCompleter怎么用?Python completion.WordCompleter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.completion
的用法示例。
在下文中一共展示了completion.WordCompleter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: interact
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def interact(connection):
# When a client is connected, erase the screen from the client and say
# Hello.
connection.send("Welcome!\n")
# Display prompt with bottom toolbar.
animal_completer = WordCompleter(["alligator", "ant"])
def get_toolbar():
return "Bottom toolbar..."
session = PromptSession()
result = await session.prompt_async(
"Say something: ", bottom_toolbar=get_toolbar, completer=animal_completer
)
connection.send("You said: {}\n".format(result))
connection.send("Bye.\n")
示例2: choose_shard
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def choose_shard(self,
shards) -> Optional[str]:
if len(shards) == 0:
raise HermitError("Not enough shards to reconstruct secret.")
shardnames = [shard.name for shard in shards]
shardnames.sort()
shardCompleter = WordCompleter(shardnames, sentence=True)
while True:
prompt_string = "Choose shard\n(options: {} or <enter> to quit)\n> "
prompt_msg = prompt_string.format(", ".join(shardnames))
shard_name = prompt(prompt_msg,
completer=shardCompleter,
**self.options).strip()
if shard_name in shardnames:
return shard_name
if shard_name == '':
return None
print("Shard not found.")
示例3: get_completer
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def get_completer(self):
standard_completions = list({word for d in self._command_descs for word in d.command.split()}) # Use a set to ensure unicity of words
standard_completions += ['quit', 'help', 'exit']
if PromptData.Wallet:
for addr in PromptData.Wallet.Addresses:
if addr not in self._known_things:
self._known_things.append(addr)
for alias in PromptData.Wallet.NamedAddr:
if alias.Title not in self._known_things:
self._known_things.append(alias.Title)
for tkn in PromptData.Wallet.GetTokens().values():
if tkn.symbol not in self._known_things:
self._known_things.append(tkn.symbol)
all_completions = standard_completions + self._known_things
PromptInterface.prompt_completer = WordCompleter(all_completions)
return PromptInterface.prompt_completer
示例4: get_roll
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def get_roll(player_name, roll_names):
if os.environ.get('PYCHARM_HOSTED') == "1":
print(Fore.LIGHTRED_EX + "Warning: Cannot use fancy prompt dialog in PyCharm.")
print(Fore.LIGHTRED_EX + "Run this app outside of PyCharm to see it in action.")
val = input(Fore.LIGHTYELLOW_EX + "What is your roll: ")
print(Fore.WHITE)
return val
print(f"Available rolls: {', '.join(roll_names)}.")
# word_comp = WordCompleter(roll_names)
word_comp = PlayComplete()
roll = prompt(f"{player_name}, what is your roll: ", completer=word_comp)
if not roll or roll not in roll_names:
print(f"Sorry {player_name}, {roll} not valid!")
return None
return roll
# def get_roll(player_name, roll_names):
# print("Available rolls:")
# for index, r in enumerate(roll_names, start=1):
# print(f"{index}. {r}")
#
# text = input(f"{player_name}, what is your roll? ")
# selected_index = int(text) - 1
#
# if selected_index < 0 or selected_index >= len(rolls):
# print(f"Sorry {player_name}, {text} is out of bounds!")
# return None
#
# return roll_names[selected_index]
#
示例5: _do_shell
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def _do_shell(_args):
commands = ['compile', 'convert', 'help', 'exit']
completer = WordCompleter(commands, WORD=True)
user_home = os.path.expanduser('~')
history = FileHistory(os.path.join(user_home, '.asn1tools-history.txt'))
session = PromptSession(completer=completer,
complete_while_typing=True,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
history=history)
input_spec = None
output_spec = None
output_codec = None
print("\nWelcome to the asn1tools shell!\n")
while True:
try:
line = session.prompt(u'$ ')
except EOFError:
return
line = line.strip()
if line:
if line.startswith('compile'):
input_spec, output_spec, output_codec = _handle_command_compile(line)
elif line.startswith('convert'):
_handle_command_convert(line,
input_spec,
output_spec,
output_codec)
elif line == 'help':
_handle_command_help()
elif line == 'exit':
return
else:
print('{}: command not found'.format(line))
示例6: completer
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def completer():
s = set()
history_strings = history().load_history_strings()
for name in history_strings:
s.add(name)
return WordCompleter(list(s), ignore_case=True)
示例7: __init__
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def __init__(self, request, logger, config):
self.request = request
self.config = config
self.logger = logger
self.cmds = {
"exploit": self._exploit,
"check": self._check,
"list": self._list,
}
self.auto_cmds = WordCompleter(["quit", "list", "check", "exploit"], ignore_case=True)
self.history = FileHistory('.drupwn-history')
self._load()
示例8: _add_completions
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def _add_completions(self):
return WordCompleter([str(i) for i in range(9)])
示例9: _sleep_completions
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def _sleep_completions(self):
return WordCompleter([str(i) for i in range(1, 60)])
示例10: _completer_for_command
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def _completer_for_command(self, command):
if not hasattr(self, "_%s_completions" % command):
return WordCompleter([])
return getattr(self, "_%s_completions" % command)()
示例11: run
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def run(self):
"""Runs the interface and waits for user input commands."""
completer = WordCompleter(['show', 'name', 'field', 'fields',
'dump', 'recalculate', 'clear', 'back'])
history = FileHistory(self._polym_path + '/.linterface_history')
session = PromptSession(history=history)
while True:
try:
command = session.prompt(HTML("<bold>PH:cap/t%d/<red>%s</red> > </bold>" %
(self._tindex, self._l.name)),
completer=completer,
complete_style=CompleteStyle.READLINE_LIKE,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True)
except KeyboardInterrupt:
self.exit_program()
continue
# Argument parsing
command = command.split(" ")
if command[0] in self.EXIT:
self.exit_program()
elif command[0] in self.RET:
break
elif command[0] in ["s", "show"]:
self._show(command)
elif command[0] == "name":
self._name(command)
elif command[0] in ["field", "f"]:
self._field(command)
elif command[0] in ["fields", "fs"]:
self._fields(command)
elif command[0] in ["dump", "d"]:
self._dump(command)
elif command[0] in ["recalculate", "r"]:
self._recalculate(command)
elif command[0] == "clear":
Interface._clear()
elif command[0] == "":
continue
else:
Interface._wrong_command()
示例12: run
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def run(self):
"""Runs the interface and waits for user input commands."""
completer = WordCompleter(['show', 'dissect', 'template', 'wireshark',
'clear', 'back'])
history = FileHistory(self._polym_path + '/.tlinterface_history')
session = PromptSession(history=history)
while True:
try:
command = session.prompt(HTML("<bold>PH:<red>cap</red> > </bold>"),
completer=completer,
complete_style=CompleteStyle.READLINE_LIKE,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True)
except KeyboardInterrupt:
self.exit_program()
continue
command = command.split(" ")
if command[0] in self.EXIT:
self.exit_program()
elif command[0] in self.RET:
break
elif command[0] in ["show", "s"]:
self._show(command)
elif command[0] == "dissect":
self._dissect(command)
elif command[0] in ["template", "t"]:
self._template(command)
elif command[0] in ["wireshark", "w"]:
self._wireshark(command)
elif command[0] == "clear":
Interface._clear()
elif command[0] == "":
continue
else:
Interface._wrong_command()
示例13: run
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def run(self):
"""Runs the interface and waits for user input commands."""
completer = WordCompleter(['capture', 'spoof', 'clear', 'import'])
history = FileHistory(self._polym_path + '/.minterface_history')
session = PromptSession(history=history)
while True:
try:
command = session.prompt(HTML("<bold><red>PH</red> > </bold>"),
completer=completer,
complete_style=CompleteStyle.READLINE_LIKE,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True)
except KeyboardInterrupt:
self.exit_program()
continue
command = command.split(" ")
if command[0] in self.EXIT:
self.exit_program()
elif command[0] in ["capture", "c"]:
self._capture(command)
elif command[0] in ["spoof", "s"]:
self._spoof(command)
elif command[0] in ["import", "i"]:
self._import(command)
elif command[0] == "clear":
Interface._clear()
elif command[0] == "":
continue
else:
Interface._wrong_command()
示例14: yes_no_prompt
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def yes_no_prompt(title, default=True):
result = prompt(title, completer=WordCompleter(['yes', 'no']),
validator=SetValidator(['yes', 'no'],
show_possible=True),
default="yes" if default else "no")
return result == 'yes'
示例15: __init__
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import WordCompleter [as 别名]
def __init__(self):
# Completer for full command names.
self._command_completer = WordCompleter(
sorted(COMMANDS_TO_HANDLERS.keys()),
ignore_case=True, WORD=True, match_middle=True)
# Completer for aliases.
self._aliases_completer = WordCompleter(
sorted(ALIASES.keys()),
ignore_case=True, WORD=True, match_middle=True)