feat: config option to disable specific ui modules
This commit is contained in:
parent
333d853b2f
commit
ed378363a0
|
@ -1,5 +1,8 @@
|
|||
local default_config = {
|
||||
input = {
|
||||
-- Set to false to disable the vim.ui.input implementation
|
||||
enabled = true,
|
||||
|
||||
-- Default prompt string
|
||||
default_prompt = "➤ ",
|
||||
|
||||
|
@ -27,6 +30,9 @@ local default_config = {
|
|||
get_config = nil,
|
||||
},
|
||||
select = {
|
||||
-- Set to false to disable the vim.ui.select implementation
|
||||
enabled = true,
|
||||
|
||||
-- Priority list of preferred vim.select implementations
|
||||
backend = { "telescope", "fzf_lua", "fzf", "builtin", "nui" },
|
||||
|
||||
|
|
|
@ -1,30 +1,44 @@
|
|||
local config = require("dressing.config")
|
||||
|
||||
local M = {}
|
||||
local all_modules = { "input", "select" }
|
||||
local original_mods = {}
|
||||
|
||||
M.setup = function(opts)
|
||||
config.update(opts)
|
||||
for _, name in ipairs(all_modules) do
|
||||
if not config[name].enabled then
|
||||
M.unpatch(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local original_input
|
||||
local original_select
|
||||
|
||||
M.patch = function()
|
||||
-- For Neovim before 0.6
|
||||
if not vim.ui then
|
||||
vim.ui = {}
|
||||
end
|
||||
if not original_input then
|
||||
original_input = vim.ui.input
|
||||
original_select = vim.ui.select
|
||||
|
||||
for _, name in ipairs(all_modules) do
|
||||
if config[name].enabled and original_mods[name] == nil then
|
||||
original_mods[name] = vim.ui[name]
|
||||
vim.ui[name] = require(string.format("dressing.%s", name))
|
||||
end
|
||||
end
|
||||
vim.ui.input = require("dressing.input")
|
||||
vim.ui.select = require("dressing.select")
|
||||
end
|
||||
|
||||
M.unpatch = function()
|
||||
vim.ui.input = original_input
|
||||
vim.ui.select = original_select
|
||||
M.unpatch = function(names)
|
||||
if not names then
|
||||
names = all_modules
|
||||
elseif type(names) ~= "table" then
|
||||
names = { names }
|
||||
end
|
||||
for _, name in ipairs(names) do
|
||||
local mod = require(string.format("dressing.%s", name))
|
||||
if vim.ui[name] == mod then
|
||||
vim.ui[name] = original_mods[name]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Reference in New Issue