feat(config): get config for snack with defaults and custom opts

This commit is contained in:
Folke Lemaitre 2024-11-04 10:14:38 +01:00
parent 7ceeb47e54
commit b3d08beb8c
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 5 additions and 5 deletions

View file

@ -107,7 +107,7 @@ function M.new(opts)
local self = setmetatable({}, { __index = M })
id = id + 1
self.id = id
opts = vim.tbl_deep_extend("force", {}, Snacks.config.get("float", defaults), opts or {})
opts = Snacks.config.get("float", defaults, opts)
opts =
vim.tbl_deep_extend("force", {}, vim.deepcopy(opts.position == "float" and defaults_float or defaults_split), opts)
if opts.win.style == "minimal" then

View file

@ -43,10 +43,10 @@ M.config = setmetatable({}, {
---@generic T: table
---@param snack string
---@param defaults T
---@param opts? T
---@return T
function M.config.get(snack, defaults)
config[snack] = vim.tbl_deep_extend("force", {}, defaults, config[snack] or {})
return config[snack]
function M.config.get(snack, defaults, opts)
return vim.tbl_deep_extend("force", {}, vim.deepcopy(defaults), vim.deepcopy(config[snack] or {}), opts or {})
end
---@param opts snacks.Opts?

View file

@ -54,7 +54,7 @@ local terminals = {}
---@param opts? snacks.terminal.Config
function M.open(cmd, opts)
---@type snacks.terminal.Config
opts = vim.tbl_deep_extend("force", {}, Snacks.config.get("terminal", defaults), opts or {})
opts = Snacks.config.get("terminal", defaults, opts)
opts.float.position = opts.float.position or (cmd and "float" or "bottom")
opts.float.wo.winbar = opts.float.wo.winbar
or (opts.float.position == "float" and "" or (vim.v.count1 .. ": %{b:term_title}"))