Skip to content

Commit

Permalink
feat(notify): added plain renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 25, 2022
1 parent a810700 commit 345fccc
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lua/noice/view/backend/notify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,36 @@ function NotifyView:update_options()
self._opts = vim.tbl_deep_extend("force", defaults, self._opts)
end

function NotifyView:plain()
return function(bufnr, notif)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, notif.message)
end
end

---@param config notify.Config
---@param render? notify.RenderFun
---@return notify.RenderFun
function NotifyView:get_render(config)
function NotifyView:get_render(config, render)
---@type string|notify.RenderFun
local ret = config.render()
local ret = render or config.render()
if type(ret) == "string" then
---@type notify.RenderFun
ret = require("notify.render")[ret]
if ret == "plain" then
ret = self:plain()
else
---@type notify.RenderFun
ret = require("notify.render")[ret]
end
end
return ret
end

---@param messages NoiceMessage[]
function NotifyView:notify_render(messages)
---@param render? notify.RenderFun
function NotifyView:notify_render(messages, render)
---@param config notify.Config
return function(buf, notif, hl, config)
-- run notify view
self:get_render(config)(buf, notif, hl, config)
self:get_render(config, render)(buf, notif, hl, config)

Util.tag(buf, "notify")

Expand Down Expand Up @@ -132,7 +144,7 @@ function NotifyView:_notify(msg)
end
self.win = nil
end,
render = Util.protect(self:notify_render(msg.messages)),
render = Util.protect(self:notify_render(msg.messages, self._opts.render)),
}

if msg.opts then
Expand Down

0 comments on commit 345fccc

Please sign in to comment.