nvim-tree.lua/lua/nvim-tree/notify.lua
kylo252 6ca6f99e76
feat(notify): add notify.threshold (#1693)
* feat: configurable notification level

add `notify.threshold` to setup opts

* feat: configurable notification level: add threshold example doc

* feat: configurable notification level: log always comes last

Co-authored-by: Alexander Courtis <alex@courtis.org>
2022-11-01 10:24:40 +11:00

45 lines
971 B
Lua

local M = {}
local config = {
threshold = vim.log.levels.INFO,
}
local modes = {
{ name = "trace", level = vim.log.levels.TRACE },
{ name = "debug", level = vim.log.levels.DEBUG },
{ name = "info", level = vim.log.levels.INFO },
{ name = "warn", level = vim.log.levels.WARN },
{ name = "error", level = vim.log.levels.ERROR },
}
do
local has_notify, notify_plugin = pcall(require, "notify")
local dispatch = function(level, msg)
if level < config.threshold then
return
end
vim.schedule(function()
if has_notify and notify_plugin then
notify_plugin(msg, level, { title = "NvimTree" })
else
vim.notify("[NvimTree] " .. msg, level)
end
end)
end
for _, x in ipairs(modes) do
M[x.name] = function(msg, ...)
return dispatch(x.level, msg, ...)
end
end
end
function M.setup(opts)
opts = opts or {}
config.threshold = opts.notify.threshold or vim.log.levels.INFO
end
return M