Skip to content

Commit

Permalink
feat: config option to disable specific ui modules
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 18, 2022
1 parent 333d853 commit ed37836
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lua/dressing/config.lua
Original file line number Diff line number Diff line change
@@ -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 = "",

Expand Down Expand Up @@ -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" },

Expand Down
36 changes: 25 additions & 11 deletions lua/dressing/init.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ed37836

Please sign in to comment.