Skip to content

Commit

Permalink
feat(notifier): allow setting dynamic options
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 7, 2024
1 parent cdc9f24 commit 36e9f45
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lua/snacks/notifier.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local M = setmetatable({}, {
---@field ft? string
---@field keep? fun(notif: snacks.notifier.Notif): boolean
---@field style? snacks.notifier.style
---@field opts? fun(notif: snacks.notifier.Notif) -- dynamic opts

--- Notification object
---@class snacks.notifier.Notif: snacks.notifier.Notif.opts
Expand Down Expand Up @@ -140,6 +141,7 @@ N.styles = {
}

---@alias snacks.notifier.level "trace"|"debug"|"info"|"warn"|"error"

---@type table<number, snacks.notifier.level>
N.levels = {
[vim.log.levels.TRACE] = "trace",
Expand Down Expand Up @@ -304,6 +306,9 @@ end

---@param notif snacks.notifier.Notif
function N:render(notif)
if type(notif.opts) == "function" then
notif.opts(notif)
end
local win = notif.win
or Snacks.win({
show = false,
Expand Down Expand Up @@ -346,6 +351,7 @@ function N:render(notif)
},
}
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {})
render(buf, notif, ctx)
vim.bo[buf].modifiable = false

Expand Down Expand Up @@ -434,7 +440,7 @@ function N:layout()
for _, notif in ipairs(self.queue) do
local skip = shown >= max_visible
if not skip then
if not notif.win or notif.dirty or not notif.win:buf_valid() then
if not notif.win or notif.dirty or not notif.win:buf_valid() or type(notif.opts) == "function" then
notif.dirty = false
self:render(notif)
---@diagnostic disable-next-line: assign-type-mismatch
Expand Down

0 comments on commit 36e9f45

Please sign in to comment.