feat(toggle): add silent field to toggle to customize behavior of notifications

This commit is contained in:
Iordanis Petkakis 2024-10-26 21:24:59 +03:00
parent cb40a09538
commit 7e354ab795

View file

@ -8,6 +8,7 @@ local M = {}
---@field color_disabled? string ---@field color_disabled? string
---@field get fun():boolean ---@field get fun():boolean
---@field set fun(state:boolean) ---@field set fun(state:boolean)
---@field silent? boolean
---@class lazyvim.Toggle.wrap: lazyvim.Toggle ---@class lazyvim.Toggle.wrap: lazyvim.Toggle
---@operator call:boolean ---@operator call:boolean
@ -18,9 +19,9 @@ function M.wrap(toggle)
__call = function() __call = function()
toggle.set(not toggle.get()) toggle.set(not toggle.get())
local state = toggle.get() local state = toggle.get()
if state then if state and not toggle.silent then
LazyVim.info("Enabled " .. toggle.name, { title = toggle.name }) LazyVim.info("Enabled " .. toggle.name, { title = toggle.name })
else elseif not state and not toggle.silent then
LazyVim.warn("Disabled " .. toggle.name, { title = toggle.name }) LazyVim.warn("Disabled " .. toggle.name, { title = toggle.name })
end end
return state return state