本文整理匯總了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(),
})