feat: display notification in greenhouse (wip)

notify-display
sammyette 2024-04-27 21:56:38 -04:00
parent 42ab856e45
commit a02de409fa
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 42 additions and 5 deletions

View File

@ -47,3 +47,12 @@ end)
bait.catch('hilbish.notification', function(notif)
doNotifyPrompt()
end)
hilbish.timeout(function()
hilbish.messages.send {
icon = '',
title = 'Warning',
text = 'Do NOT use Hilbish at 3AM!',
channel = 'your-walls'
}
end, 5000)

View File

@ -7,11 +7,30 @@ local terminal = require 'terminal'
local Greenhouse = require 'nature.greenhouse'
local Page = require 'nature.greenhouse.page'
local display = ''
local gh
local ticker
bait.catch('hilbish.notification', function(message)
if not gh then return end
local inverted = false
local msgDisplay = string.format('(%s #%s) %s: %s', message.icon, message.channel, message.title, message.summary or message.text)
ticker = hilbish.interval(function()
inverted = not inverted
display = inverted and msgDisplay or lunacolors.invert(msgDisplay)
gh:render()
end, 500)
display = msgDisplay
hilbish.timeout(function()
ticker:stop()
end, 20000)
end)
commander.register('greenhouse', function(args, sinks)
local gh = Greenhouse(sinks.out)
gh = Greenhouse(sinks.out)
local buffer = ''
local display = ''
local command = false
local commands = {
q = function()
@ -45,7 +64,7 @@ commander.register('greenhouse', function(args, sinks)
if not self.isSpecial then
self.sink:writeln(lunacolors.format(string.format('{grayBg} ↳ Page %d%s{reset}', self.curPage, workingPage.title and '' .. workingPage.title .. ' ' or '')))
end
self.sink:write(buffer == '' and display or buffer)
self.sink:write(self:sub(buffer == '' and display or buffer, self.horizOffset, self.region.width))
end
function gh:input(c)
-- command handling
@ -121,4 +140,9 @@ example: greenhouse hello.md]]
ansikit.hideCursor()
gh:initUi()
local oldQuit = gh.quit
function gh:quit()
ticker:stop()
--oldQuit(gh)
end
end)

View File

@ -305,13 +305,17 @@ function Greenhouse:initUi()
ansikit.clear(true)
self:draw()
function self:quit()
done = true
end
while not done do
local c = read()
self:keybind('Ctrl-Q', function()
done = true
self:quit()
end)
self:keybind('Ctrl-D', function()
done = true
self:quit()
end)
if self.keybinds[c] then