mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
3.2 KiB
3.2 KiB
🍿 notifier
🚀 Usage
-- to replace an existing notification just use the same id.
-- you can also use the return value of the notify function as id.
for i = 1, 10 do
vim.defer_fn(function()
vim.notify("Hello " .. i, "info", { id = "test" })
end, i * 500)
end
⚙️ Config
---@class snacks.notifier.Config
---@field keep? fun(notif: snacks.notifier.Notif): boolean # global keep function
{
timeout = 3000, -- default timeout in ms
width = { min = 40, max = 0.4 },
height = { min = 1, max = 0.6 },
-- editor margin to keep free. tabline and statusline are taken into account automatically
margin = { top = 0, right = 1, bottom = 0 },
padding = true, -- add 1 cell of left/right padding to the notification window
sort = { "level", "added" }, -- sort by level and time
icons = {
error = " ",
warn = " ",
info = " ",
debug = " ",
trace = " ",
},
---@type snacks.notifier.style
style = "compact",
}
🎨 Styles
notification
{
border = "rounded",
zindex = 100,
wo = {
winblend = 5,
wrap = false,
},
bo = { filetype = "markdown" },
}
📚 Types
Render styles:
- compact: use border for icon and title
- minimal: no border, only icon and message
- fancy: similar to the default nvim-notify style
---@alias snacks.notifier.style snacks.notifier.render|"compact"|"fancy"|"minimal"
Notifications
Notification options
---@class snacks.notifier.Notif.opts
---@field id? number|string
---@field msg? string
---@field level? number|snacks.notifier.level
---@field title? string
---@field icon? string
---@field timeout? number
---@field ft? string
---@field keep? fun(notif: snacks.notifier.Notif): boolean
---@field style? snacks.notifier.style
Notification object
---@class snacks.notifier.Notif: snacks.notifier.Notif.opts
---@field msg string
---@field id number|string
---@field win? snacks.win
---@field icon string
---@field level snacks.notifier.level
---@field timeout number
---@field dirty? boolean
---@field shown? number timestamp in ms
---@field added number timestamp in ms
---@field added_hr number hrtime in ms
---@field layout? { width: number, height: number, top?: number }
Rendering
---@alias snacks.notifier.render fun(buf: number, notif: snacks.notifier.Notif, ctx: snacks.notifier.ctx)
---@class snacks.notifier.hl
---@field title string
---@field icon string
---@field border string
---@field footer string
---@field msg string
---@class snacks.notifier.ctx
---@field opts snacks.win.Config
---@field notifier snacks.notifier
---@field hl snacks.notifier.hl
---@field ns number
📦 Module
Snacks.notifier()
---@type fun(msg: string, level?: snacks.notifier.level|number, opts?: snacks.notifier.Notif.opts): number|string
Snacks.notifier()
Snacks.notifier.hide()
---@param id? number|string
Snacks.notifier.hide(id)
Snacks.notifier.notify()
---@param msg string
---@param level? snacks.notifier.level|number
---@param opts? snacks.notifier.Notif.opts
Snacks.notifier.notify(msg, level, opts)