wrapper around `fn.input` to prevent exception with `<C-c>`

main
bhagwan 2 years ago
parent 3511c44753
commit fa90b74e31

@ -460,7 +460,7 @@ M.git_checkout = function(selected, opts)
local cmd_checkout = path.git_cwd({"git", "checkout"}, opts)
local cmd_cur_commit = path.git_cwd({"git", "rev-parse", "--short HEAD"}, opts)
local commit_hash = selected[1]:match("[^ ]+")
if vim.fn.input("Checkout commit " .. commit_hash .. "? [y/n] ") == "y" then
if utils.input("Checkout commit " .. commit_hash .. "? [y/n] ") == "y" then
local current_commit = utils.io_systemlist(cmd_cur_commit)
if(commit_hash == current_commit) then return end
table.insert(cmd_checkout, commit_hash)
@ -509,7 +509,7 @@ M.git_stash_drop = function(selected, opts)
end
M.git_stash_pop = function(selected, opts)
if vim.fn.input("Pop " .. #selected .. " stash(es)? [y/n] ") == "y" then
if utils.input("Pop " .. #selected .. " stash(es)? [y/n] ") == "y" then
local cmd = path.git_cwd({"git", "stash", "pop"}, opts)
git_exec(selected, opts, cmd)
vim.cmd("e!")
@ -517,7 +517,7 @@ M.git_stash_pop = function(selected, opts)
end
M.git_stash_apply = function(selected, opts)
if vim.fn.input("Apply " .. #selected .. " stash(es)? [y/n] ") == "y" then
if utils.input("Apply " .. #selected .. " stash(es)? [y/n] ") == "y" then
local cmd = path.git_cwd({"git", "stash", "apply"}, opts)
git_exec(selected, opts, cmd)
vim.cmd("e!")

@ -124,7 +124,7 @@ M.grep = function(opts)
-- if user did not provide a search term
-- provide an input prompt
if not opts.search and not opts.raw_cmd then
opts.search = vim.fn.input(opts.input_prompt) or ''
opts.search = utils.input(opts.input_prompt) or ''
end
-- search query in header line

@ -150,7 +150,7 @@ M.grep = function(opts)
end
if not opts.search then
opts.search = vim.fn.input(opts.input_prompt or 'Grep For> ')
opts.search = utils.input(opts.input_prompt or 'Grep For> ')
end
return M.tags(opts)

@ -611,6 +611,13 @@ function M.io_system(cmd, use_lua_io)
end
end
-- wrapper around |input()| to allow cancellation with `<C-c>`
-- without "E5108: Error executing lua Keyboard interrupt"
function M.input(prompt, text)
local ok, res = pcall(vim.fn.input, prompt, text or '')
return ok and res or nil
end
function M.fzf_bind_to_neovim(key)
local conv_map = {
['alt'] = 'A',

Loading…
Cancel
Save