Add some more UI to neovim

main
Ensar Sarajčić 2022-05-05 12:14:06 +02:00
parent c0e9c0cdf0
commit b57cf14024
4 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,9 @@
-- UI extensions
local plenary_async = require("plenary.async.async")
local M = {}
M.input = plenary_async.wrap(vim.ui.input, 2)
M.select = plenary_async.wrap(vim.ui.select, 3)
return M

View File

@ -33,6 +33,8 @@ return require("packer").startup({
use("romainl/vim-devdocs") -- Quick DevDocs.io search using :DD use("romainl/vim-devdocs") -- Quick DevDocs.io search using :DD
use("gpanders/editorconfig.nvim") -- .editorconfig support use("gpanders/editorconfig.nvim") -- .editorconfig support
use("lewis6991/impatient.nvim") -- Caching lua modules for faster startup use("lewis6991/impatient.nvim") -- Caching lua modules for faster startup
use("rcarriga/nvim-notify") -- notifications UI
use("MunifTanjim/nui.nvim") -- General UI
-- Tools -- Tools
use("direnv/direnv.vim") -- Integration with Direnv use("direnv/direnv.vim") -- Integration with Direnv

View File

@ -21,6 +21,7 @@ require("telescope").setup({
}) })
require("telescope").load_extension("dap") require("telescope").load_extension("dap")
require("telescope").load_extension("notify")
vim.keymap.set("n", "<C-P>", function() vim.keymap.set("n", "<C-P>", function()
require("telescope.builtin").find_files() require("telescope.builtin").find_files()

View File

@ -0,0 +1,81 @@
-- UI setup
local input = require("nui.input")
local event = require("nui.utils.autocmd").event
-- Notifications
local notify = require("notify")
notify.setup({
render = "minimal",
stages = "static",
})
vim.notify = notify
-- Inputs
local input_ui
vim.ui.input = function(opts, on_confirm)
if input_ui then
-- ensure single ui.input operation
vim.notify("busy: another input is pending!", vim.log.levels.WARN)
return
end
local function on_done(value)
if input_ui then
-- if it's still mounted, unmount it
input_ui:unmount()
end
-- pass the input value
on_confirm(value)
-- indicate the operation is done
input_ui = nil
end
local border_top_text = opts.prompt or "[Input]"
local default_value = opts.default
input_ui = input({
relative = "cursor",
position = {
row = 1,
col = 0,
},
size = {
-- minimum width 20
width = math.max(20, type(default_value) == "string" and #default_value or 0),
},
border = {
style = "rounded",
highlight = "Normal",
text = {
top = border_top_text,
top_align = "left",
},
},
win_options = {
winhighlight = "Normal:Normal",
},
}, {
default_value = default_value,
on_close = function()
on_done(nil)
end,
on_submit = function(value)
on_done(value)
end,
})
input_ui:mount()
-- cancel operation if cursor leaves input
input_ui:on(event.BufLeave, function()
on_done(nil)
end, { once = true })
-- cancel operation if <Esc> is pressed
input_ui:map("n", "<Esc>", function()
on_done(nil)
end, { noremap = true, nowait = true })
end
-- Selections