Skip to content

Commit

Permalink
feat: expose number pending
Browse files Browse the repository at this point in the history
Closes #120
  • Loading branch information
rcarriga committed Oct 13, 2022
1 parent 56f65a9 commit f9560a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 9 additions & 1 deletion doc/nvim-notify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ notify.setup({user_config}) *notify.setup()*
}

Parameters: ~
{user_config} (notify.Config)
{user_config} (notify.Config|nil)

See: ~
|notify-render()|
Expand Down Expand Up @@ -164,6 +164,14 @@ notify.dismiss({opts}) *notify.dismiss()*
were dismissed.


notify.pending() *notify.pending()*
Number of notifications currently waiting to be displayed


Return: ~
table<integer, integer>


notify.instance({user_config}, {inherit}) *notify.instance()*
Configure an instance of nvim-notify. You can use this to manage a separate
instance of nvim-notify with completely different configuration. The
Expand Down
15 changes: 14 additions & 1 deletion lua/notify/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local global_instance, global_config
--- See: ~
--- |notify.Config|
---</pre>
---@param user_config notify.Config
---@param user_config notify.Config | nil
---@eval { ['description'] = require('notify.config')._format_default() }
---@see notify-render
function notify.setup(user_config)
Expand Down Expand Up @@ -126,6 +126,15 @@ function notify.dismiss(opts)
return global_instance.dismiss(opts)
end

---Number of notifications currently waiting to be displayed
---@return table<integer, integer>
function notify.pending()
if not global_instance then
notify.setup()
end
return global_instance.pending()
end

function notify._print_history()
if not global_instance then
notify.setup()
Expand Down Expand Up @@ -254,6 +263,10 @@ function notify.instance(user_config, inherit)
end
end

function instance.pending()
return service and service:pending() or {}
end

setmetatable(instance, {
__call = function(_, m, l, o)
if vim.in_fast_event() then
Expand Down
4 changes: 4 additions & 0 deletions lua/notify/service/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ function NotificationService:dismiss(opts)
end
end

function NotificationService:pending()
return self._pending:length()
end

---@return NotificationService
return function(config, animator)
return NotificationService:new(config, animator)
Expand Down

0 comments on commit f9560a2

Please sign in to comment.