From 38b8083b6d458e188a1d4d6d6e5e23835056bdab Mon Sep 17 00:00:00 2001 From: sammyette Date: Mon, 10 Jul 2023 19:02:28 -0400 Subject: [PATCH] feat: show unread notification in right prompt in default config --- .hilbishrc.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/.hilbishrc.lua b/.hilbishrc.lua index a12486e..249f97e 100644 --- a/.hilbishrc.lua +++ b/.hilbishrc.lua @@ -4,16 +4,36 @@ local lunacolors = require 'lunacolors' local bait = require 'bait' local ansikit = require 'ansikit' +local unreadCount = 0 +local running = false local function doPrompt(fail) hilbish.prompt(lunacolors.format( '{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ ' )) end +local function doNotifyPrompt() + if running or unreadCount == hilbish.messages.unreadCount() then return end + + local notifPrompt = string.format('• %s unread notification%s', hilbish.messages.unreadCount(), hilbish.messages.unreadCount() > 1 and 's' or '') + unreadCount = hilbish.messages.unreadCount() + hilbish.prompt(lunacolors.blue(notifPrompt), 'right') + + hilbish.timeout(function() + hilbish.prompt('', 'right') + end, 3000) +end + doPrompt() +bait.catch('command.preexec', function() + running = true +end) + bait.catch('command.exit', function(code) + running = false doPrompt(code ~= 0) + doNotifyPrompt() end) bait.catch('hilbish.vimMode', function(mode) @@ -24,11 +44,6 @@ bait.catch('hilbish.vimMode', function(mode) end end) -bait.catch('hilbish.notification', function() - 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') - end, 3000) +bait.catch('hilbish.notification', function(notif) + doNotifyPrompt() end)