feat: use virtual title in notifications if title is not supported (#2439)

* feat: use virtual title in notifications if title is not supported

* Fix boolean expressions

* Replace `pcall` with `package.loaded`

* Detect title support before sending notification

* Prevent `title_support` from being nil after evaluation

* temporary stylua suppression

---------

Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
Azad
2023-10-07 03:40:39 +02:00
committed by GitHub
parent d8e495b235
commit 85abe29396
2 changed files with 23 additions and 9 deletions

View File

@@ -5,6 +5,21 @@ local config = {
absolute_path = true,
}
local title_support
function M.supports_title()
-- TODO increase stylua column_width
-- stylua: ignore start
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
-- stylua: ignore end
return title_support
end
local modes = {
{ name = "trace", level = vim.log.levels.TRACE },
{ name = "debug", level = vim.log.levels.DEBUG },
@@ -20,6 +35,10 @@ do
end
vim.schedule(function()
if not M.supports_title() then
msg = "[NvimTree]\n" .. msg
end
vim.notify(msg, level, { title = "NvimTree" })
end)
end