diff options
-rw-r--r-- | lua/lvim/core/builtins/init.lua | 1 | ||||
-rw-r--r-- | lua/lvim/core/log.lua | 57 | ||||
-rw-r--r-- | lua/lvim/core/notify.lua | 31 | ||||
-rw-r--r-- | lua/lvim/plugins.lua | 5 | ||||
-rw-r--r-- | lua/onedarker/Notify.lua | 24 | ||||
-rw-r--r-- | lua/onedarker/init.lua | 2 |
6 files changed, 95 insertions, 25 deletions
diff --git a/lua/lvim/core/builtins/init.lua b/lua/lvim/core/builtins/init.lua index 8f83072e..315deed3 100644 --- a/lua/lvim/core/builtins/init.lua +++ b/lua/lvim/core/builtins/init.lua @@ -15,6 +15,7 @@ local builtins = { "lvim.core.bufferline", "lvim.core.autopairs", "lvim.core.comment", + "lvim.core.notify", "lvim.core.lualine", } diff --git a/lua/lvim/core/log.lua b/lua/lvim/core/log.lua index 502fd19b..557590e1 100644 --- a/lua/lvim/core/log.lua +++ b/lua/lvim/core/log.lua @@ -1,6 +1,7 @@ local Log = {} local logfile = string.format("%s/%s.log", vim.fn.stdpath "cache", "lvim") +local in_headless = #vim.api.nvim_list_uis() == 0 Log.levels = { TRACE = 1, @@ -33,7 +34,7 @@ function Log:init() nvim_notify_params_injecter(nil, {}) local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] - structlog.configure { + local lvim_log = { lvim = { sinks = { structlog.sinks.Console(log_level, { @@ -49,25 +50,6 @@ function Log:init() { level = structlog.formatters.FormatColorizer.color_level() } ), }), - structlog.sinks.NvimNotify(Log.levels.INFO, { - processors = { - nvim_notify_default_namer, - nvim_notify_params_injecter, - }, - formatter = structlog.formatters.Format( -- - "%s", - { "msg" }, - { blacklist_all = true } - ), - params_map = { - icon = "icon", - keep = "keep", - on_open = "on_open", - on_close = "on_close", - timeout = "timeout", - title = "title", - }, - }), structlog.sinks.File(Log.levels.TRACE, logfile, { processors = { structlog.processors.Namer(), @@ -83,12 +65,39 @@ function Log:init() }, } + if not in_headless and lvim.builtin.notify.active then + table.insert( + lvim_log.lvim.sinks, + structlog.sinks.NvimNotify(Log.levels.INFO, { + processors = { + nvim_notify_default_namer, + nvim_notify_params_injecter, + }, + formatter = structlog.formatters.Format( -- + "%s", + { "msg" }, + { blacklist_all = true } + ), + params_map = { + icon = "icon", + keep = "keep", + on_open = "on_open", + on_close = "on_close", + timeout = "timeout", + title = "title", + }, + }) + ) + end + + structlog.configure(lvim_log) + local logger = structlog.get_logger "lvim" - if lvim.log.override_notify then + if not in_headless and lvim.builtin.notify.active and lvim.log.override_notify then -- Overwrite vim.notify to use the logger vim.notify = function(msg, vim_log_level, opts) - nvim_notify_params = opts or {} + nvim_notify_params = vim.tbl_deep_extend("force", lvim.builtin.notify.opts, opts) -- vim_log_level can be omitted if vim_log_level == nil then vim_log_level = Log.levels["INFO"] @@ -109,7 +118,7 @@ end ---@param level string [same as vim.log.log_levels] function Log:add_entry(level, msg, event) if self.__handle then - self.__handle:log(level, msg, event) + self.__handle:log(level, vim.inspect(msg), event) return end @@ -119,7 +128,7 @@ function Log:add_entry(level, msg, event) end self.__handle = logger - self.__handle:log(level, msg, event) + self.__handle:log(level, vim.inspect(msg), event) end ---Retrieves the path of the logfile diff --git a/lua/lvim/core/notify.lua b/lua/lvim/core/notify.lua new file mode 100644 index 00000000..7d222a89 --- /dev/null +++ b/lua/lvim/core/notify.lua @@ -0,0 +1,31 @@ +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 (see below for details) + stages = "fade_in_slide_out", + + ---@usage Default timeout for notifications + timeout = 5000, + + ---@usage For stages that change opacity this is treated as the highlight behind the window + background_colour = pallete.fg, + + ---@usage Icons for the different levels + icons = { + ERROR = "", + WARN = "", + INFO = "", + DEBUG = "", + TRACE = "✎", + }, + }, + } +end + +return M diff --git a/lua/lvim/plugins.lua b/lua/lvim/plugins.lua index a178eba5..976e5141 100644 --- a/lua/lvim/plugins.lua +++ b/lua/lvim/plugins.lua @@ -8,7 +8,10 @@ return { { "williamboman/nvim-lsp-installer", }, - { "rcarriga/nvim-notify" }, + { + "rcarriga/nvim-notify", + disable = not lvim.builtin.notify.active, + }, { "Tastyep/structlog.nvim" }, { "nvim-lua/popup.nvim" }, diff --git a/lua/onedarker/Notify.lua b/lua/onedarker/Notify.lua new file mode 100644 index 00000000..4eebc00e --- /dev/null +++ b/lua/onedarker/Notify.lua @@ -0,0 +1,24 @@ +local Notify = { + NotifyERRORBorder = { fg = C.error_red }, + NotifyWARNBorder = { fg = C.warning_orange }, + NotifyINFOBorder = { fg = C.green }, + NotifyDEBUGBorder = { fg = C.purple_test }, + NotifyTRACEBorder = { fg = C.purple }, + NotifyERRORIcon = { fg = C.error_red }, + NotifyWARNIcon = { fg = C.warning_orange }, + NotifyINFOIcon = { fg = C.green }, + NotifyDEBUGIcon = { fg = C.purple_test }, + NotifyTRACEIcon = { fg = C.purple }, + NotifyERRORTitle = { fg = C.error_red }, + NotifyWARNTitle = { fg = C.warning_orange }, + NotifyINFOTitle = { fg = C.green }, + NotifyDEBUGTitle = { fg = C.purple_test }, + NotifyTRACETitle = { fg = C.purple }, + NotifyERRORBody = { fg = C.fg }, + NotifyWARNBody = { fg = C.fg }, + NotifyINFOBody = { fg = C.fg }, + NotifyDEBUGBody = { fg = C.fg }, + NotifyTRACEBody = { fg = C.fg }, +} + +return Notify diff --git a/lua/onedarker/init.lua b/lua/onedarker/init.lua index 73043ac3..dec56afa 100644 --- a/lua/onedarker/init.lua +++ b/lua/onedarker/init.lua @@ -13,6 +13,7 @@ local highlights = require "onedarker.highlights" local Treesitter = require "onedarker.Treesitter" local markdown = require "onedarker.markdown" local Whichkey = require "onedarker.Whichkey" +local Notify = require "onedarker.Notify" local Git = require "onedarker.Git" local LSP = require "onedarker.LSP" local diff = require "onedarker.diff" @@ -22,6 +23,7 @@ local skeletons = { Treesitter, markdown, Whichkey, + Notify, Git, LSP, diff, |