From a02de409fa6594b0d98bd943ee8fef371b44706f Mon Sep 17 00:00:00 2001 From: sammyette Date: Sat, 27 Apr 2024 21:56:38 -0400 Subject: [PATCH] feat: display notification in greenhouse (wip) --- .hilbishrc.lua | 9 +++++++++ nature/commands/greenhouse.lua | 30 +++++++++++++++++++++++++++--- nature/greenhouse/init.lua | 8 ++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.hilbishrc.lua b/.hilbishrc.lua index 249f97e..3cab0a5 100644 --- a/.hilbishrc.lua +++ b/.hilbishrc.lua @@ -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) diff --git a/nature/commands/greenhouse.lua b/nature/commands/greenhouse.lua index 9c155b0..36e26ff 100644 --- a/nature/commands/greenhouse.lua +++ b/nature/commands/greenhouse.lua @@ -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) diff --git a/nature/greenhouse/init.lua b/nature/greenhouse/init.lua index e58faf7..29de2fc 100644 --- a/nature/greenhouse/init.lua +++ b/nature/greenhouse/init.lua @@ -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