From f02d4784fb9335ec161a5d51ffa7c417c16021ef Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 10 Jul 2023 18:27:00 -0400 Subject: [PATCH] feat: show amount of unread notifs in default config, add unreadCount function --- .hilbishrc.lua | 9 ++------- nature/hummingbird.lua | 7 +++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.hilbishrc.lua b/.hilbishrc.lua index 1596e02..a12486e 100644 --- a/.hilbishrc.lua +++ b/.hilbishrc.lua @@ -24,14 +24,9 @@ bait.catch('hilbish.vimMode', function(mode) end end) ---[[ -hilbish.timeout(function() - hilbish.messages.send {title = 'greetings!', text = 'hello world :D'} -end, 2000) -]]-- - bait.catch('hilbish.notification', function() - hilbish.prompt(lunacolors.blue('• 1 new notification'), 'right') + local notif = string.format('• %s unread notification%s', hilbish.messages.unreadCount(), hilbish.messages.unreadCount() > 1 and 's' or '') + hilbish.prompt(lunacolors.blue(notif), 'right') hilbish.timeout(function() hilbish.prompt('', 'right') diff --git a/nature/hummingbird.lua b/nature/hummingbird.lua index 56c28b2..581e92c 100644 --- a/nature/hummingbird.lua +++ b/nature/hummingbird.lua @@ -4,6 +4,7 @@ local lunacolors = require 'lunacolors' local M = {} local counter = 0 +local unread = 0 M._messages = {} M.icons = { INFO = '', @@ -35,6 +36,7 @@ function hilbish.messages.send(message) expect(message, 'text') expect(message, 'title') counter = counter + 1 + unread = unread + 1 message.index = counter message.read = false @@ -46,6 +48,7 @@ function hilbish.messages.read(idx) local msg = M._messages[idx] if msg then M._messages[idx].read = true + unread = unread - 1 end end @@ -55,6 +58,10 @@ function hilbish.messages.readAll(idx) end end +function hilbish.messages.unreadCount() + return unread +end + function hilbish.messages.delete(idx) local msg = M._messages[idx] if not msg then