2022-03-24 01:46:21 +00:00
|
|
|
local all_modules = { "input", "select" }
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
-- For Neovim before 0.6
|
|
|
|
if not vim.ui then
|
|
|
|
vim.ui = {}
|
|
|
|
end
|
|
|
|
|
2022-08-28 17:48:05 +00:00
|
|
|
local enabled_mods = {}
|
2022-03-24 01:46:21 +00:00
|
|
|
M.original_mods = {}
|
|
|
|
|
2024-01-16 03:24:30 +00:00
|
|
|
---@param key string
|
|
|
|
---@return boolean?
|
|
|
|
M.is_enabled = function(key)
|
|
|
|
local enabled = enabled_mods[key]
|
|
|
|
if enabled == nil then
|
|
|
|
enabled = require("dressing.config")[key].enabled
|
|
|
|
end
|
|
|
|
return enabled
|
|
|
|
end
|
|
|
|
|
2022-08-28 17:48:05 +00:00
|
|
|
for _, key in ipairs(all_modules) do
|
|
|
|
M.original_mods[key] = vim.ui[key]
|
|
|
|
vim.ui[key] = function(...)
|
2024-01-16 03:24:30 +00:00
|
|
|
if M.is_enabled(key) then
|
2022-08-28 17:48:05 +00:00
|
|
|
require(string.format("dressing.%s", key))(...)
|
|
|
|
else
|
|
|
|
return M.original_mods[key](...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
---Patch or unpatch all vim.ui methods
|
|
|
|
---@param enabled? boolean When nil, use the default from config
|
2022-03-24 01:46:21 +00:00
|
|
|
M.all = function(enabled)
|
|
|
|
for _, name in ipairs(all_modules) do
|
|
|
|
M.mod(name, enabled)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-28 17:48:05 +00:00
|
|
|
---@param name string
|
|
|
|
---@param enabled? boolean When nil, use the default from config
|
2022-03-24 01:46:21 +00:00
|
|
|
M.mod = function(name, enabled)
|
2022-08-28 17:48:05 +00:00
|
|
|
enabled_mods[name] = enabled
|
2022-03-24 01:46:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|