[fix] fix notify's highlight groups and make it optional (#1827)

This commit is contained in:
kylo252 2021-10-22 23:46:43 +02:00 committed by GitHub
parent 10df0b5ffd
commit a96a44a16a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 95 additions and 25 deletions

View file

@ -15,6 +15,7 @@ local builtins = {
"lvim.core.bufferline", "lvim.core.bufferline",
"lvim.core.autopairs", "lvim.core.autopairs",
"lvim.core.comment", "lvim.core.comment",
"lvim.core.notify",
"lvim.core.lualine", "lvim.core.lualine",
} }

View file

@ -1,6 +1,7 @@
local Log = {} local Log = {}
local logfile = string.format("%s/%s.log", vim.fn.stdpath "cache", "lvim") local logfile = string.format("%s/%s.log", vim.fn.stdpath "cache", "lvim")
local in_headless = #vim.api.nvim_list_uis() == 0
Log.levels = { Log.levels = {
TRACE = 1, TRACE = 1,
@ -33,7 +34,7 @@ function Log:init()
nvim_notify_params_injecter(nil, {}) nvim_notify_params_injecter(nil, {})
local log_level = Log.levels[(lvim.log.level):upper() or "WARN"] local log_level = Log.levels[(lvim.log.level):upper() or "WARN"]
structlog.configure { local lvim_log = {
lvim = { lvim = {
sinks = { sinks = {
structlog.sinks.Console(log_level, { structlog.sinks.Console(log_level, {
@ -49,25 +50,6 @@ function Log:init()
{ level = structlog.formatters.FormatColorizer.color_level() } { 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, { structlog.sinks.File(Log.levels.TRACE, logfile, {
processors = { processors = {
structlog.processors.Namer(), 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" 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 -- Overwrite vim.notify to use the logger
vim.notify = function(msg, vim_log_level, opts) 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 -- vim_log_level can be omitted
if vim_log_level == nil then if vim_log_level == nil then
vim_log_level = Log.levels["INFO"] vim_log_level = Log.levels["INFO"]
@ -109,7 +118,7 @@ end
---@param level string [same as vim.log.log_levels] ---@param level string [same as vim.log.log_levels]
function Log:add_entry(level, msg, event) function Log:add_entry(level, msg, event)
if self.__handle then if self.__handle then
self.__handle:log(level, msg, event) self.__handle:log(level, vim.inspect(msg), event)
return return
end end
@ -119,7 +128,7 @@ function Log:add_entry(level, msg, event)
end end
self.__handle = logger self.__handle = logger
self.__handle:log(level, msg, event) self.__handle:log(level, vim.inspect(msg), event)
end end
---Retrieves the path of the logfile ---Retrieves the path of the logfile

31
lua/lvim/core/notify.lua Normal file
View 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

View file

@ -8,7 +8,10 @@ return {
{ {
"williamboman/nvim-lsp-installer", "williamboman/nvim-lsp-installer",
}, },
{ "rcarriga/nvim-notify" }, {
"rcarriga/nvim-notify",
disable = not lvim.builtin.notify.active,
},
{ "Tastyep/structlog.nvim" }, { "Tastyep/structlog.nvim" },
{ "nvim-lua/popup.nvim" }, { "nvim-lua/popup.nvim" },

24
lua/onedarker/Notify.lua Normal file
View 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

View file

@ -13,6 +13,7 @@ local highlights = require "onedarker.highlights"
local Treesitter = require "onedarker.Treesitter" local Treesitter = require "onedarker.Treesitter"
local markdown = require "onedarker.markdown" local markdown = require "onedarker.markdown"
local Whichkey = require "onedarker.Whichkey" local Whichkey = require "onedarker.Whichkey"
local Notify = require "onedarker.Notify"
local Git = require "onedarker.Git" local Git = require "onedarker.Git"
local LSP = require "onedarker.LSP" local LSP = require "onedarker.LSP"
local diff = require "onedarker.diff" local diff = require "onedarker.diff"
@ -22,6 +23,7 @@ local skeletons = {
Treesitter, Treesitter,
markdown, markdown,
Whichkey, Whichkey,
Notify,
Git, Git,
LSP, LSP,
diff, diff,