mirror of https://github.com/Hilbis/Hilbish
feat: show unread notification in right prompt in default config
parent
d63a10d699
commit
38b8083b6d
|
@ -4,16 +4,36 @@ local lunacolors = require 'lunacolors'
|
||||||
local bait = require 'bait'
|
local bait = require 'bait'
|
||||||
local ansikit = require 'ansikit'
|
local ansikit = require 'ansikit'
|
||||||
|
|
||||||
|
local unreadCount = 0
|
||||||
|
local running = false
|
||||||
local function doPrompt(fail)
|
local function doPrompt(fail)
|
||||||
hilbish.prompt(lunacolors.format(
|
hilbish.prompt(lunacolors.format(
|
||||||
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
|
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
|
||||||
))
|
))
|
||||||
end
|
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()
|
doPrompt()
|
||||||
|
|
||||||
|
bait.catch('command.preexec', function()
|
||||||
|
running = true
|
||||||
|
end)
|
||||||
|
|
||||||
bait.catch('command.exit', function(code)
|
bait.catch('command.exit', function(code)
|
||||||
|
running = false
|
||||||
doPrompt(code ~= 0)
|
doPrompt(code ~= 0)
|
||||||
|
doNotifyPrompt()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
bait.catch('hilbish.vimMode', function(mode)
|
bait.catch('hilbish.vimMode', function(mode)
|
||||||
|
@ -24,11 +44,6 @@ bait.catch('hilbish.vimMode', function(mode)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
bait.catch('hilbish.notification', function()
|
bait.catch('hilbish.notification', function(notif)
|
||||||
local notif = string.format('• %s unread notification%s', hilbish.messages.unreadCount(), hilbish.messages.unreadCount() > 1 and 's' or '')
|
doNotifyPrompt()
|
||||||
hilbish.prompt(lunacolors.blue(notif), 'right')
|
|
||||||
|
|
||||||
hilbish.timeout(function()
|
|
||||||
hilbish.prompt('', 'right')
|
|
||||||
end, 3000)
|
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue