mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
docs: notifier
This commit is contained in:
parent
9ffcea77f1
commit
6bbc7df37a
2 changed files with 67 additions and 58 deletions
|
@ -42,22 +42,6 @@
|
|||
|
||||
## 📚 Types
|
||||
|
||||
```lua
|
||||
---@alias snacks.notifier.hl "title"|"icon"|"border"|"footer"|"msg"
|
||||
```
|
||||
|
||||
```lua
|
||||
---@class snacks.notifier.ctx
|
||||
---@field opts snacks.win.Config
|
||||
---@field notifier snacks.notifier
|
||||
---@field hl table<snacks.notifier.hl, string>
|
||||
---@field ns number
|
||||
```
|
||||
|
||||
```lua
|
||||
---@alias snacks.notifier.render fun(buf: number, notif: snacks.notifier.Notif, ctx: snacks.notifier.ctx)
|
||||
```
|
||||
|
||||
Render styles:
|
||||
* compact: simple border title with message
|
||||
* fancy: similar to the default nvim-notify style
|
||||
|
@ -66,6 +50,10 @@ Render styles:
|
|||
---@alias snacks.notifier.style snacks.notifier.render|"compact"|"fancy"
|
||||
```
|
||||
|
||||
### Notifications
|
||||
|
||||
Notification options
|
||||
|
||||
```lua
|
||||
---@class snacks.notifier.Notif.opts
|
||||
---@field id? number|string
|
||||
|
@ -80,6 +68,8 @@ Render styles:
|
|||
---@field style? snacks.notifier.style
|
||||
```
|
||||
|
||||
Notification object
|
||||
|
||||
```lua
|
||||
---@class snacks.notifier.Notif: snacks.notifier.Notif.opts
|
||||
---@field msg string
|
||||
|
@ -94,7 +84,23 @@ Render styles:
|
|||
---@field layout? { width: number, height: number, top?: number }
|
||||
```
|
||||
|
||||
Public functions
|
||||
### Rendering
|
||||
|
||||
```lua
|
||||
---@alias snacks.notifier.render fun(buf: number, notif: snacks.notifier.Notif, ctx: snacks.notifier.ctx)
|
||||
```
|
||||
|
||||
```lua
|
||||
---@alias snacks.notifier.hl "title"|"icon"|"border"|"footer"|"msg"
|
||||
```
|
||||
|
||||
```lua
|
||||
---@class snacks.notifier.ctx
|
||||
---@field opts snacks.win.Config
|
||||
---@field notifier snacks.notifier
|
||||
---@field hl table<snacks.notifier.hl, string>
|
||||
---@field ns number
|
||||
```
|
||||
|
||||
## 📦 Module
|
||||
|
||||
|
|
|
@ -7,6 +7,50 @@ local M = setmetatable({}, {
|
|||
end,
|
||||
})
|
||||
|
||||
--- Render styles:
|
||||
--- * compact: simple border title with message
|
||||
--- * fancy: similar to the default nvim-notify style
|
||||
---@alias snacks.notifier.style snacks.notifier.render|"compact"|"fancy"
|
||||
|
||||
--- ### 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 once? boolean
|
||||
---@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 layout? { width: number, height: number, top?: number }
|
||||
|
||||
--- ### Rendering
|
||||
---@alias snacks.notifier.render fun(buf: number, notif: snacks.notifier.Notif, ctx: snacks.notifier.ctx)
|
||||
|
||||
---@alias snacks.notifier.hl "title"|"icon"|"border"|"footer"|"msg"
|
||||
|
||||
---@class snacks.notifier.ctx
|
||||
---@field opts snacks.win.Config
|
||||
---@field notifier snacks.notifier
|
||||
---@field hl table<snacks.notifier.hl, string>
|
||||
---@field ns number
|
||||
|
||||
Snacks.config.style("notification", {
|
||||
border = "rounded",
|
||||
zindex = 100,
|
||||
|
@ -24,21 +68,6 @@ local N = {}
|
|||
|
||||
N.ns = vim.api.nvim_create_namespace("snacks.notifier")
|
||||
|
||||
---@alias snacks.notifier.hl "title"|"icon"|"border"|"footer"|"msg"
|
||||
|
||||
---@class snacks.notifier.ctx
|
||||
---@field opts snacks.win.Config
|
||||
---@field notifier snacks.notifier
|
||||
---@field hl table<snacks.notifier.hl, string>
|
||||
---@field ns number
|
||||
|
||||
---@alias snacks.notifier.render fun(buf: number, notif: snacks.notifier.Notif, ctx: snacks.notifier.ctx)
|
||||
|
||||
--- Render styles:
|
||||
--- * compact: simple border title with message
|
||||
--- * fancy: similar to the default nvim-notify style
|
||||
---@alias snacks.notifier.style snacks.notifier.render|"compact"|"fancy"
|
||||
|
||||
---@type table<string, snacks.notifier.render>
|
||||
N.styles = {
|
||||
-- compact style using border title
|
||||
|
@ -115,30 +144,6 @@ local function hl(name, level)
|
|||
return "SnacksNotifier" .. name .. (level and (level:sub(1, 1):upper() .. level:sub(2):lower()) or "")
|
||||
end
|
||||
|
||||
---@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 once? boolean
|
||||
---@field ft? string
|
||||
---@field keep? fun(notif: snacks.notifier.Notif): boolean
|
||||
---@field style? snacks.notifier.style
|
||||
|
||||
---@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 layout? { width: number, height: number, top?: number }
|
||||
|
||||
local _id = 0
|
||||
|
||||
local function next_id()
|
||||
|
@ -427,8 +432,6 @@ end
|
|||
-- Global instance
|
||||
local notifier = N.new()
|
||||
|
||||
-- Public functions
|
||||
|
||||
---@param msg string
|
||||
---@param level? snacks.notifier.level|number
|
||||
---@param opts? snacks.notifier.Notif.opts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue