clear prompt with normal :<esc> and fix file creation

This commit is contained in:
kyazdani42 2020-03-01 15:00:34 +01:00
parent c31cceaff6
commit 7ac26175f2
2 changed files with 10 additions and 7 deletions

View File

@ -20,7 +20,8 @@ end
local function print_err(err) local function print_err(err)
if err ~= nil then if err ~= nil then
api.nvim_command('echohl ErrorMsg') api.nvim_command('echohl ErrorMsg')
api.nvim_command('echomsg "'..err..'"') -- remove the \n with string.sub
api.nvim_command('echomsg "'..string.sub(err, 0, -2)..'"')
api.nvim_command('echohl None') api.nvim_command('echohl None')
end end
end end
@ -48,9 +49,9 @@ local function rename(file, new_path)
system('mv '..file..' '..new_path) system('mv '..file..' '..new_path)
end end
local function create(file, folders) local function create(path, file, folders)
if folders ~= "" then system('mkdir -p '..folders) end if folders ~= "" then system('mkdir -p '..folders) end
if file ~= nil then system('touch ' ..folders..file) end if file ~= nil then system('touch '..path..folders..file) end
end end
return { return {

View File

@ -16,12 +16,11 @@ local function input(v)
end end
local function clear_prompt() local function clear_prompt()
api.nvim_command('echo "\r' .. string.rep(" ", 200) .. '\n"') api.nvim_command('normal :<esc>')
end end
local function create_file(path) local function create_file(path)
local new_file = input("Create file: " .. path) local new_file = input("Create file: " .. path)
clear_prompt()
local file = nil local file = nil
if not string.match(new_file, '.*/$') then if not string.match(new_file, '.*/$') then
@ -32,11 +31,14 @@ local function create_file(path)
local folders = "" local folders = ""
if #new_file ~= 0 then if #new_file ~= 0 then
for p in string.gmatch(new_file, '[^/]*') do for p in string.gmatch(new_file, '[^/]*') do
folders = folders .. p .. '/' if p and p ~= "" then
folders = folders .. p .. '/'
end
end end
end end
create(file, folders) clear_prompt()
create(path, file, folders)
refresh_git() refresh_git()
refresh_tree() refresh_tree()
update_view() update_view()