本文整理汇总了Python中prompt_toolkit.completion.PathCompleter方法的典型用法代码示例。如果您正苦于以下问题:Python completion.PathCompleter方法的具体用法?Python completion.PathCompleter怎么用?Python completion.PathCompleter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.completion
的用法示例。
在下文中一共展示了completion.PathCompleter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_open_file
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import PathCompleter [as 别名]
def do_open_file():
async def coroutine():
open_dialog = TextInputDialog(
title="Open file",
label_text="Enter the path of a file:",
completer=PathCompleter(),
)
path = await show_dialog_as_float(open_dialog)
ApplicationState.current_path = path
if path is not None:
try:
with open(path, "rb") as f:
text_field.text = f.read().decode("utf-8", errors="ignore")
except IOError as e:
show_message("Error", "{}".format(e))
ensure_future(coroutine())
示例2: get_path_matches
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import PathCompleter [as 别名]
def get_path_matches(self, _, word_before_cursor):
completer = PathCompleter(expanduser=True)
document = Document(
text=word_before_cursor, cursor_position=len(word_before_cursor)
)
for c in completer.get_completions(document, None):
yield Match(completion=c, priority=(0,))
示例3: get_path_matches
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import PathCompleter [as 别名]
def get_path_matches(self, _, word_before_cursor):
# pylint: disable=no-self-use
# function cannot be static since it has to be a callable for get_completions
completer = PathCompleter(expanduser=True)
document = Document(text=word_before_cursor,
cursor_position=len(word_before_cursor))
for c in completer.get_completions(document, None):
yield Match(completion=c, priority=(0,))
示例4: create_command_completer
# 需要导入模块: from prompt_toolkit import completion [as 别名]
# 或者: from prompt_toolkit.completion import PathCompleter [as 别名]
def create_command_completer(editor):
commands = [c + ' ' for c in get_commands()]
return GrammarCompleter(COMMAND_GRAMMAR, {
'command': WordCompleter(commands),
'location': PathCompleter(expanduser=True),
'set_option': WordCompleter(sorted(SET_COMMANDS)),
'buffer_name': BufferNameCompleter(editor),
'colorscheme': ColorSchemeCompleter(editor),
'shell_command': SystemCompleter(),
})