From 49b9798cbcc92b18258f84a21e34b3717964096e Mon Sep 17 00:00:00 2001 From: kyazdani42 Date: Thu, 20 Feb 2020 17:55:59 +0100 Subject: [PATCH] clear vim prompt when updating the fs --- lua/lib/fs.lua | 11 ++++++++--- lua/lib/fs_update.lua | 23 +++++++++++++++++------ lua/lib/state.lua | 3 ++- lua/lib/winutils.lua | 1 + 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lua/lib/fs.lua b/lua/lib/fs.lua index adc3357d..9201ed3c 100644 --- a/lua/lib/fs.lua +++ b/lua/lib/fs.lua @@ -36,15 +36,20 @@ local function rm(path) end local function rename(file, new_path) - return luv.fs_rename(file, new_path) + luv.fs_rename(file, new_path, function(err) + if err ~= nil then + -- TODO: display error somehow. + -- it wont work with vim.api + end + end) end return { check_dir_access = check_dir_access; - is_dir = is_dir; is_symlink = is_symlink; link_to = link_to; get_cwd = get_cwd; - rm = rm; + is_dir = is_dir; rename = rename; + rm = rm; } diff --git a/lua/lib/fs_update.lua b/lua/lib/fs_update.lua index b8322dd2..284da5d6 100644 --- a/lua/lib/fs_update.lua +++ b/lua/lib/fs_update.lua @@ -1,22 +1,31 @@ local api = vim.api -local system = function(v) api.nvim_call_function('system', { v }) end + local update_view = require 'lib/winutils'.update_view local refresh_tree = require 'lib/state'.refresh_tree local refresh_git = require 'lib/git'.refresh_git - local rm = require 'lib/fs'.rm local rename = require 'lib/fs'.rename -local input = function(v) +local function system(v) + api.nvim_call_function('system', { v }) +end + +local function input(v) local param if type(v) == 'string' then param = { v } else param = v end return api.nvim_call_function('input', param) end +local function clear_prompt() + api.nvim_command('echo "\r' .. string.rep(" ", 80) .. '"') +end + local function create_file(path) -- TODO: create files dynamically local new_file = input("Create file: " .. path) local new_path = path .. new_file + clear_prompt() + -- TODO: replace system() calls with luv calls if string.match(new_file, '.*/$') then system('mkdir -p ' .. new_path) else @@ -28,8 +37,9 @@ local function create_file(path) end local function remove_file(filename, path) - local confirm = input("Remove " .. filename .. " ? y/n: ") - if string.match(confirm, 'y.*$') ~= nil then + local ans = input("Remove " .. filename .. " ? y/n: ") + clear_prompt() + if ans == "y" then rm(path .. filename) refresh_git() refresh_tree() @@ -38,7 +48,8 @@ local function remove_file(filename, path) end local function rename_file(filename, path) - local new_path = input({"Rename file " .. filename .. " : ", path .. filename}) + local new_path = input({"Rename file " .. filename .. ": ", path .. filename}) + clear_prompt() rename(path .. filename, new_path) refresh_git() refresh_tree() diff --git a/lua/lib/state.lua b/lua/lib/state.lua index fed2de7f..0e4c2805 100644 --- a/lua/lib/state.lua +++ b/lua/lib/state.lua @@ -7,6 +7,7 @@ local fs = require 'lib/fs' local is_dir = fs.is_dir local is_symlink = fs.is_symlink local get_cwd = fs.get_cwd +local link_to = fs.link_to local ROOT_PATH = get_cwd() .. '/' @@ -117,7 +118,7 @@ local function open_dir(tree_index) next_node = Tree[next_index] end else - local dirlist = list_dirs(node.path .. node.name) + local dirlist = list_dirs('"' .. node.path .. node.name ..'"') local child_dirs = create_nodes(node.path .. node.name .. '/', node.relpath, node.depth + 1, dirlist) for i, n in pairs(child_dirs) do diff --git a/lua/lib/winutils.lua b/lua/lib/winutils.lua index c86058b2..9da75180 100644 --- a/lua/lib/winutils.lua +++ b/lua/lib/winutils.lua @@ -95,6 +95,7 @@ local function set_mappings() local mappings = { [''] = 'open_file("edit")'; ['<2-LeftMouse>'] = 'open_file("edit")'; + ['<2-RightMouse>'] = 'open_file("chdir")'; [''] = 'open_file("vsplit")'; [''] = 'open_file("split")'; [''] = 'open_file("chdir")';