From 34f595f876f6b559f17c9960cb7b83e1765164f5 Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:44:48 +0100 Subject: [PATCH] fix: display icon on notices for `nvim-notify` --- README.md | 2 +- lua/rip-substitute/config.lua | 2 +- lua/rip-substitute/utils.lua | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35d7db7..bdcbd15 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ require("rip-substitute").setup { }, notification = { onSuccess = true, - icon = "", -- requires `snacks.nvim` + icon = "", } } ``` diff --git a/lua/rip-substitute/config.lua b/lua/rip-substitute/config.lua index 28b053a..94d2f58 100644 --- a/lua/rip-substitute/config.lua +++ b/lua/rip-substitute/config.lua @@ -52,7 +52,7 @@ local defaultConfig = { }, notification = { onSuccess = true, - icon = "", -- requires `snacks.nvim` + icon = "", }, } diff --git a/lua/rip-substitute/utils.lua b/lua/rip-substitute/utils.lua index f60b9f4..8f74244 100644 --- a/lua/rip-substitute/utils.lua +++ b/lua/rip-substitute/utils.lua @@ -6,7 +6,12 @@ local M = {} function M.notify(msg, level) if not level then level = "info" end local icon = require("rip-substitute.config").config.notification.icon - vim.notify(msg, vim.log.levels[level:upper()], { title = "rip-substitute", icon = icon }) + local opts = { title = "rip-substitute", icon = icon } + + -- since nvim-notify does not support the `icon` field that snacks.nvim + if package.loaded["notify"] then opts.title = vim.trim(icon .. opts.title) end + + vim.notify(msg, vim.log.levels[level:upper()], opts) end ---@return number startLnum