Python prompt_toolkit.completion.PathCompleter() Examples

The following are 4 code examples of prompt_toolkit.completion.PathCompleter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module prompt_toolkit.completion , or try the search function .
Example #1
Source File: text-editor.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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()) 
Example #2
Source File: pgcompleter.py    From pgcli with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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,)) 
Example #3
Source File: mssqlcompleter.py    From mssql-cli with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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,)) 
Example #4
Source File: completer.py    From pyvim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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(),
    })