Procházet zdrojové kódy

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

kylo252 před 3 roky
rodič
revize
a96a44a16a

+ 1 - 0
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",
 }
 

+ 33 - 24
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

+ 31 - 0
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

+ 4 - 1
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" },

+ 24 - 0
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

+ 2 - 0
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,