mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-30 06:39:33 +02:00
[fix] fix notify's highlight groups and make it optional (#1827)
This commit is contained in:
parent
10df0b5ffd
commit
a96a44a16a
6 changed files with 95 additions and 25 deletions
|
@ -15,6 +15,7 @@ local builtins = {
|
|||
"lvim.core.bufferline",
|
||||
"lvim.core.autopairs",
|
||||
"lvim.core.comment",
|
||||
"lvim.core.notify",
|
||||
"lvim.core.lualine",
|
||||
}
|
||||
|
||||
|
|
|
@ -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,6 +50,24 @@ function Log:init()
|
|||
{ level = structlog.formatters.FormatColorizer.color_level() }
|
||||
),
|
||||
}),
|
||||
structlog.sinks.File(Log.levels.TRACE, logfile, {
|
||||
processors = {
|
||||
structlog.processors.Namer(),
|
||||
structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3, stack_level = 2 }),
|
||||
structlog.processors.Timestamper "%H:%M:%S",
|
||||
},
|
||||
formatter = structlog.formatters.Format( --
|
||||
"%s [%-5s] %s: %-30s",
|
||||
{ "timestamp", "level", "logger_name", "msg" }
|
||||
),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -67,28 +86,18 @@ function Log:init()
|
|||
timeout = "timeout",
|
||||
title = "title",
|
||||
},
|
||||
}),
|
||||
structlog.sinks.File(Log.levels.TRACE, logfile, {
|
||||
processors = {
|
||||
structlog.processors.Namer(),
|
||||
structlog.processors.StackWriter({ "line", "file" }, { max_parents = 3, stack_level = 2 }),
|
||||
structlog.processors.Timestamper "%H:%M:%S",
|
||||
},
|
||||
formatter = structlog.formatters.Format( --
|
||||
"%s [%-5s] %s: %-30s",
|
||||
{ "timestamp", "level", "logger_name", "msg" }
|
||||
),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
)
|
||||
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
|
||||
|
|
31
lua/lvim/core/notify.lua
Normal file
31
lua/lvim/core/notify.lua
Normal file
|
@ -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
|
|
@ -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" },
|
||||
|
|
24
lua/onedarker/Notify.lua
Normal file
24
lua/onedarker/Notify.lua
Normal file
|
@ -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
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue