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) bait.catch('hilbish.notification', function(notif)
doNotifyPrompt() doNotifyPrompt()
end) 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 Greenhouse = require 'nature.greenhouse'
local Page = require 'nature.greenhouse.page' 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) commander.register('greenhouse', function(args, sinks)
local gh = Greenhouse(sinks.out) gh = Greenhouse(sinks.out)
local buffer = '' local buffer = ''
local display = ''
local command = false local command = false
local commands = { local commands = {
q = function() q = function()
@ -45,7 +64,7 @@ commander.register('greenhouse', function(args, sinks)
if not self.isSpecial then 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 ''))) self.sink:writeln(lunacolors.format(string.format('{grayBg} ↳ Page %d%s{reset}', self.curPage, workingPage.title and '' .. workingPage.title .. ' ' or '')))
end 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 end
function gh:input(c) function gh:input(c)
-- command handling -- command handling
@ -121,4 +140,9 @@ example: greenhouse hello.md]]
ansikit.hideCursor() ansikit.hideCursor()
gh:initUi() gh:initUi()
local oldQuit = gh.quit
function gh:quit()
ticker:stop()
--oldQuit(gh)
end
end) end)

View File

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