Skip to content

Commit

Permalink
feat: display notification in greenhouse (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
TorchedSammy committed Apr 28, 2024
1 parent 42ab856 commit a02de40
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .hilbishrc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
30 changes: 27 additions & 3 deletions nature/commands/greenhouse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
8 changes: 6 additions & 2 deletions nature/greenhouse/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a02de40

Please sign in to comment.