refactor(nvim): improve appearance of notifications

This commit is contained in:
Price Hiller 2024-03-13 21:55:50 -05:00
parent 4e406baa08
commit 6165c01128
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -56,7 +56,6 @@ return {
}, },
}, },
dependencies = { dependencies = {
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
"MunifTanjim/nui.nvim", "MunifTanjim/nui.nvim",
{ {
"rcarriga/nvim-notify", "rcarriga/nvim-notify",
@ -73,38 +72,79 @@ return {
desc = "Notifications: Dismiss", desc = "Notifications: Dismiss",
}, },
}, },
opts = { -- Animation style () config = function()
stages = "slide", local base = require("notify.render.base")
fps = 60,
-- Function called when a new window is opened, use for changing win settings/config local opts = {
on_open = nil, stages = "slide",
fps = 60,
on_open = function(win)
local buf = vim.api.nvim_win_get_buf(win)
local ft = vim.bo[buf].filetype
if ft == "" or ft == "notify" then
vim.api.nvim_set_option_value(
"filetype",
"markdown",
{ buf = vim.api.nvim_win_get_buf(win) }
)
vim.api.nvim_set_option_value("wrap", true, { win = win })
end
end,
render = function(bufnr, notif, highlights, _)
local left_icon = notif.icon .. " "
local max_message_width = math.max(math.max(unpack(vim.tbl_map(function(line)
return vim.fn.strchars(line)
end, notif.message))))
local right_title = notif.title[2]
local left_title = notif.title[1]
local title_accum = vim.str_utfindex(left_icon)
+ vim.str_utfindex(right_title)
+ vim.str_utfindex(left_title)
-- Function called when a window is closed local left_buffer = string.rep(" ", math.max(0, max_message_width - title_accum))
on_close = nil,
-- Render function for notifications. See notify-render() local namespace = base.namespace()
render = "default", vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, { "", "" })
vim.api.nvim_buf_set_extmark(bufnr, namespace, 0, 0, {
virt_text = {
{ left_icon, highlights.icon },
{ left_title .. left_buffer, highlights.title },
},
virt_text_win_col = 0,
priority = 10,
})
vim.api.nvim_buf_set_extmark(bufnr, namespace, 0, 0, {
virt_text = { { right_title, highlights.title } },
virt_text_pos = "right_align",
priority = 10,
})
vim.api.nvim_buf_set_lines(bufnr, 1, -1, false, notif.message)
-- Default timeout for notifications vim.api.nvim_buf_set_extmark(bufnr, namespace, 1, 0, {
timeout = 5000, hl_group = highlights.body,
end_line = #notif.message,
end_col = #notif.message[#notif.message],
priority = 50, -- Allow treesitter to override
})
end,
-- For stages that change opacity this is treated as the highlight behind the window timeout = 5000,
-- Set this to either a highlight group, an RGB hex value e.g. "#000000" or a function returning an RGB code for dynamic values -- For stages that change opacity this is treated as the highlight behind the window
background_colour = "#000000", -- Set this to either a highlight group, an RGB hex value e.g. "#000000" or a function returning an RGB code for dynamic values
background_colour = "#000000",
-- Minimum width for notification windows -- Minimum width for notification windows
minimum_width = 50, minimum_width = 50,
-- Icons for the different levels
-- Icons for the different levels icons = {
icons = { ERROR = "",
ERROR = "", WARN = "",
WARN = "", INFO = "",
INFO = "", DEBUG = "",
DEBUG = "", TRACE = "",
TRACE = "", },
}, }
}, require("notify").setup(opts)
end,
}, },
}, },
}, },