mirror of https://github.com/Hilbis/Hilbish
feat: display notification in greenhouse (wip)
parent
42ab856e45
commit
a02de409fa
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue