本文整理汇总了Python中prompt_toolkit.auto_suggest.AutoSuggestFromHistory方法的典型用法代码示例。如果您正苦于以下问题:Python auto_suggest.AutoSuggestFromHistory方法的具体用法?Python auto_suggest.AutoSuggestFromHistory怎么用?Python auto_suggest.AutoSuggestFromHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.auto_suggest
的用法示例。
在下文中一共展示了auto_suggest.AutoSuggestFromHistory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def main():
settings = Settings()
bindings = get_bindings(settings)
executor = Executor(settings)
toolbar = Toolbar(settings)
completer = KafkaCompleter(settings) if settings.enable_auto_complete else None
suggester = AutoSuggestFromHistory() if settings.enable_auto_suggest else None
history = ThreadedHistory(FileHistory(get_user_history_path())) if settings.enable_history else InMemoryHistory()
session = PromptSession(completer=completer, style=style, bottom_toolbar=toolbar.handler,
key_bindings=bindings, history=history, include_default_pygments_style=False)
while True:
try:
command = session.prompt([("class:operator", "> ")], auto_suggest=suggester)
except KeyboardInterrupt:
continue
except EOFError:
break
else:
executor.execute(command)
settings.save_settings()
示例2: prompt
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def prompt(commands, module=None):
"""Launch the prompt with the given commands
Args:
commands ([str]): List of commands to autocomplete
module (str, optional): Name of the module. Defaults to None.
Returns:
prompt session: Session of the promt
"""
default_prompt = "homePwn"
color_default_prompt = ColorSelected().theme.primary
warn = ColorSelected().theme.warn
confirm = ColorSelected().theme.confirm
html = HTML(f"<bold><{color_default_prompt}>{default_prompt} >></{color_default_prompt}></bold>")
if module:
html = HTML(f"<bold><{color_default_prompt}>{default_prompt}</{color_default_prompt}> (<{warn}>{module}</{warn}>) <{confirm}>>></{confirm}></bold> ")
data = session.prompt(
html,
completer= CustomCompleter(commands),
complete_style=CompleteStyle.READLINE_LIKE,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True)
return data
示例3: __init__
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [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()
示例4: __init__
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def __init__(self, db_path):
self.db_path = db_path
self.completer = WMCompleter(self)
self.signatures = Signatures()
self.prompt_session = PromptSession(
HTML("WMDB ≫ "),
#bottom_toolbar=functools.partial(bottom_toolbar, ts=self.teamservers),
completer=self.completer,
complete_in_thread=True,
complete_while_typing=True,
auto_suggest=AutoSuggestFromHistory(),
#rprompt=get_rprompt(False),
#style=example_style,
search_ignore_case=True
)
示例5: main
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def main():
"""
Start the Slack Client
"""
os.system("clear; figlet 'Slack Gitsin' | lolcat")
history = FileHistory(os.path.expanduser("~/.slackHistory"))
while True:
text = prompt("slack> ", history=history,
auto_suggest=AutoSuggestFromHistory(),
on_abort=AbortAction.RETRY,
style=DocumentStyle,
completer=Completer(fuzzy_match=False,
text_utils=TextUtils()),
complete_while_typing=Always(),
get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
key_bindings_registry=manager.registry,
accept_action=AcceptAction.RETURN_DOCUMENT
)
slack = Slack(text)
slack.run_command()
示例6: _do_shell
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [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))
示例7: custom_prompt
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def custom_prompt(currentSong):
session = PromptSession(
message=get_prompt,
history=history(),
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
bottom_toolbar=get_bottom_toolbar(currentSong),
completer=completer(),
complete_while_typing=True,
complete_in_thread=True,
style=style
)
return session.prompt()
示例8: shell
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def shell(self, items, pargs):
self.pargs = pargs
self.items = items
stdout.write(
'\n') # When the fetching messege ends need to add \n after \r.
self.prompt_show_items()
history = InMemoryHistory()
session = PromptSession() if PROMPT_TOOLKIT_V2 else None
while True:
kwargs = dict(
history=history,
auto_suggest=AutoSuggestFromHistory(),
completer=WGCompleter(list(self.items.keys())),
style=we_get_prompt_style
)
try:
p = prompt(u'we-get > ', **kwargs)
except TypeError as e:
log.debug('{}:{}'.format(type(e), e))
kwargs.pop('history')
if PROMPT_TOOLKIT_V2:
p = session.prompt(u'we-get > ', **kwargs)
else:
p = prompt(u'we-get > ', **kwargs)
if self.prompt_no_command(p):
continue
elif self.prompt_is_single_command(p):
command = p
args = None
else:
_ = p.split()
command = _[0]
_.pop(0)
args = ' '.join(_)
if not self.prompt_verify_command(command, args):
continue
elif not self.prompt_parse_command(command, args):
break
示例9: run
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [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()
示例10: run
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [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()
示例11: run
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [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()
示例12: create_application
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def create_application(self, full_layout=True):
""" makes the application object and the buffers """
if full_layout:
layout = create_layout(self.lexer, ExampleLexer, ToolbarLexer)
else:
layout = create_tutorial_layout(self.lexer)
buffers = {
DEFAULT_BUFFER: Buffer(is_multiline=True),
'description': Buffer(is_multiline=True, read_only=True),
'parameter' : Buffer(is_multiline=True, read_only=True),
'examples' : Buffer(is_multiline=True, read_only=True),
'bottom_toolbar' : Buffer(is_multiline=True),
'example_line' : Buffer(is_multiline=True),
'default_values' : Buffer(),
'symbols' : Buffer()
}
writing_buffer = Buffer(
history=self.history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
completer=self.completer,
complete_while_typing=Always()
)
return Application(
mouse_support=False,
style=self.styles,
buffer=writing_buffer,
on_input_timeout=self.on_input_timeout,
key_bindings_registry=registry,
layout=layout,
buffers=buffers,
)
示例13: main
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def main():
# Create some history first. (Easy for testing.)
history = InMemoryHistory()
history.append_string("import os")
history.append_string('print("hello")')
history.append_string('print("world")')
history.append_string("import path")
# Print help.
print("This CLI has fish-style auto-suggestion enable.")
print('Type for instance "pri", then you\'ll see a suggestion.')
print("Press the right arrow to insert the suggestion.")
print("Press Control-C to retry. Control-D to exit.")
print()
session = PromptSession(
history=history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
)
while True:
try:
text = session.prompt("Say something: ")
except KeyboardInterrupt:
pass # Ctrl-C pressed. Try again.
else:
break
print("You said: %s" % text)
示例14: create_buffer
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def create_buffer(self, completer, history):
return Buffer(
history=history,
auto_suggest=AutoSuggestFromHistory(),
enable_history_search=True,
completer=completer,
complete_while_typing=Always(),
accept_action=AcceptAction.RETURN_DOCUMENT)
示例15: __init__
# 需要导入模块: from prompt_toolkit import auto_suggest [as 别名]
# 或者: from prompt_toolkit.auto_suggest import AutoSuggestFromHistory [as 别名]
def __init__(self) -> None:
self.commands = self.get_commands()
self.cmd_handler = CommandHandler(self.commands)
self.completer = CommandCompleter(self.commands)
self.style = self.get_style()
self._break = False
self.prompt_session = PromptSession(completer=self.completer, style=self.style,
bottom_toolbar=self.bottom_toolbar,
auto_suggest=AutoSuggestFromHistory())
super(CommandPrompt, self).__init__()
# --------------------------------------------------------------- #