From 9017389766ff1ce31c8f0a21fe667653a7ab6b3a Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 2 Jan 2022 10:25:20 +0100 Subject: feat: lazyload notify's configuration (#1855) Co-authored-by: Luc Sinet --- lua/lvim/core/notify.lua | 84 ++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 35 deletions(-) (limited to 'lua/lvim/core/notify.lua') diff --git a/lua/lvim/core/notify.lua b/lua/lvim/core/notify.lua index 5339357b..cb62778f 100644 --- a/lua/lvim/core/notify.lua +++ b/lua/lvim/core/notify.lua @@ -1,45 +1,59 @@ local M = {} -function M.config() - local pallete = require "onedarker.palette" - - lvim.builtin.notify = { - active = false, - on_config_done = nil, - -- TODO: update after https://github.com/rcarriga/nvim-notify/pull/24 - opts = { - ---@usage Animation style one of { "fade", "slide", "fade_in_slide_out", "static" } - stages = "slide", - - ---@usage timeout for notifications in ms, default 5000 - timeout = 5000, - - ---@usage highlight behind the window for stages that change opacity - background_colour = pallete.fg, - - ---@usage Icons for the different levels - icons = { - ERROR = "", - WARN = "", - INFO = "", - DEBUG = "", - TRACE = "✎", - }, +local Log = require "lvim.core.log" + +local defaults = { + active = false, + on_config_done = nil, + opts = { + ---@usage Animation style one of { "fade", "slide", "fade_in_slide_out", "static" } + stages = "slide", + + ---@usage Function called when a new window is opened, use for changing win settings/config + on_open = nil, + + ---@usage Function called when a window is closed + on_close = nil, + + ---@usage timeout for notifications in ms, default 5000 + timeout = 5000, + + -- Render function for notifications. See notify-render() + render = "default", + + ---@usage highlight behind the window for stages that change opacity + background_colour = "Normal", + + ---@usage minimum width for notification windows + minimum_width = 50, + + ---@usage Icons for the different levels + icons = { + ERROR = "", + WARN = "", + INFO = "", + DEBUG = "", + TRACE = "✎", }, - } + }, +} + +function M.config() + lvim.builtin.notify = vim.tbl_deep_extend("force", defaults, lvim.builtin.notify or {}) end -M.params_injecter = function(_, entry) - -- FIXME: this is currently getting ignored or is not passed correctly - for key, value in pairs(lvim.builtin.notify.opts) do - entry[key] = value +function M.setup() + if #vim.api.nvim_list_uis() == 0 then + -- no need to configure notifications in headless + return end - return entry -end -M.default_namer = function(logger, entry) - entry["title"] = logger.name - return entry + local opts = lvim.builtin.notify and lvim.builtin.notify.opts or defaults + local notify = require "notify" + + notify.setup(opts) + vim.notify = notify + Log:configure_notifications(notify) end return M -- cgit v1.2.3