nvim-tree.lua/lua/nvim-tree/notify.lua
Alexander Courtis 53b0bcaada
chore: stylua column width 120 -> 140 (#2448)
* chore: stylua column width 120 -> 140

* chore: stylua column width 120 -> 140, tidy

* Revert "chore: stylua column width 120 -> 140, tidy"

This reverts commit 8a0524d6bd.

* chore: stylua column width 120 -> 140, tidy watcher.lua

* chore: stylua column width 120 -> 140, tidy diagnostics.lua

* chore: stylua column width 120 -> 140, tidy git.lua

* chore: stylua column width 120 -> 140, tidy open-file.lua

* chore: stylua column width 120 -> 140, tidy system-open.lua

* chore: stylua column width 120 -> 140, tidy runner.lua
2023-10-08 11:40:58 +11:00

65 lines
1.5 KiB
Lua

local M = {}
local config = {
threshold = vim.log.levels.INFO,
absolute_path = true,
}
local title_support
function M.supports_title()
if title_support == nil then
title_support = (package.loaded.notify and (vim.notify == require "notify" or vim.notify == require("notify").notify))
or (package.loaded.noice and (vim.notify == require("noice").notify or vim.notify == require("noice.source.notify").notify))
or (package.loaded.notifier and require("notifier.config").has_component "nvim")
or false
end
return title_support
end
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 dispatch = function(level, msg)
if level < config.threshold then
return
end
vim.schedule(function()
if not M.supports_title() then
msg = "[NvimTree]\n" .. msg
end
vim.notify(msg, level, { title = "NvimTree" })
end)
end
for _, x in ipairs(modes) do
M[x.name] = function(msg)
return dispatch(x.level, msg)
end
end
end
function M.render_path(path)
if config.absolute_path then
return path
else
return vim.fn.fnamemodify(path .. "/", ":h:t")
end
end
function M.setup(opts)
opts = opts or {}
config.threshold = opts.notify.threshold or vim.log.levels.INFO
config.absolute_path = opts.notify.absolute_path
end
return M