Esempio n. 1
0
def error(vim: Nvim, expr: typing.Any):
    """
    Prints the error messages to Vim/Nvim's :messages buffer.
    """
    if hasattr(vim, 'err_write'):
        string = (expr if isinstance(expr, str) else str(expr))
        return vim.err_write('[defx] ' + string + '\n')
    else:
        vim.call('defx#util#print_error', expr)
Esempio n. 2
0
def cwd_input(vim: Nvim,
              cwd: str,
              prompt: str,
              text: str = '',
              completion: str = '') -> str:
    """
    Returns the absolute input path in cwd.
    """
    save_cwd = vim.call('getcwd')
    vim.command('lcd {}'.format(cwd))

    filename = vim.call('input', prompt, text, completion)
    filename = os.path.normpath(os.path.join(cwd, filename))

    vim.command('lcd {}'.format(save_cwd))
    return filename
Esempio n. 3
0
def cwd_input(vim: Nvim,
              cwd: str,
              prompt: str,
              text: str = '',
              completion: str = '') -> typing.Optional[Path]:
    """
    Returns the absolute input path in cwd.
    """
    save_cwd = vim.call('getcwd')
    vim.command(f'silent lcd {cwd}')

    filename: str = vim.call('input', prompt, text, completion)
    if not filename:
        return None

    vim.command(f'silent lcd {save_cwd}')
    return Path(cwd).joinpath(filename).resolve()
Esempio n. 4
0
def confirm(vim: Nvim, question: str) -> bool:
    """
    Confirm action
    """
    option: int = vim.call('confirm', question, '&Yes\n&No\n&Cancel')
    return option is 1
Esempio n. 5
0
def error(vim: Nvim, expr: typing.Any) -> None:
    """
    Prints the error messages to Vim/Nvim's :messages buffer.
    """
    vim.call('defx#util#print_error', expr)