dotfiles/config/nvim/lua/utils.lua

30 lines
699 B
Lua

local M = {}
-- keybinding mapper
function M.map(mode, lhs, rhs, opts)
local options = { noremap = true, silent = true }
if opts then
options = vim.tbl_extend('force', options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
-- simple prompt
function M.prompt(msg, accept_msg, deny_msg)
local answer = vim.fn.input(msg .. ' (YES/no) ')
while(true) do
-- clear vim cmdline before printing anything
vim.cmd('mode')
if answer == 'YES' then
print(accept_msg)
return true
elseif string.lower(answer) == 'no' then
print(deny_msg)
return false
end
-- re-request user input
answer = vim.fn.input('Please retry: ' .. msg .. ' (YES/no) ')
end
end
return M