feat(greenhouse): add functions for custom keybinds

pull/240/head
sammyette 2023-07-09 20:22:59 -04:00
parent 60f267260b
commit 713f24aa3e
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 12 additions and 8 deletions

View File

@ -18,6 +18,12 @@ function Greenhouse:new(sink)
self.sink = sink self.sink = sink
self.pages = {} self.pages = {}
self.curPage = 1 self.curPage = 1
self.keybinds = {
['Up'] = function(self) self:scroll 'up' end,
['Down'] = function(self) self:scroll 'down' end,
['Ctrl-Left'] = self.previous,
['Ctrl-Right'] = self.next
}
return self return self
end end
@ -85,6 +91,10 @@ function Greenhouse:previous()
end end
end end
function Greenhouse:keybind(key, callback)
self.keybinds[key] = callback
end
function Greenhouse:initUi() function Greenhouse:initUi()
local ansikit = require 'ansikit' local ansikit = require 'ansikit'
local bait = require 'bait' local bait = require 'bait'
@ -114,15 +124,9 @@ function Greenhouse:initUi()
done = true done = true
end end
if c == 'Up' then if self.keybinds[c] then
self:scroll 'up' self.keybinds[c](self)
end end
if c == 'Down' then
self:scroll 'down'
end
if c == 'Ctrl-Right' then self:next() end
if c == 'Ctrl-Left' then self:previous() end
--[[ --[[
if c == 27 then if c == 27 then