diff --git a/nature/commands/greenhouse.lua b/nature/commands/greenhouse.lua index b147db4..b5a1ee4 100644 --- a/nature/commands/greenhouse.lua +++ b/nature/commands/greenhouse.lua @@ -8,6 +8,15 @@ local Page = require 'nature.greenhouse.page' commander.register('greenhouse', function(args, sinks) local gh = Greenhouse(sinks.out) + + local buffer = '' + local command = false + local commands = { + q = function() + gh.keybinds['Ctrl-D'](gh) + end + } + function gh:resize() local size = terminal.size() self.region = { @@ -15,6 +24,7 @@ commander.register('greenhouse', function(args, sinks) height = size.height - 2 } end + local oldDraw = gh.draw function gh:draw() oldDraw(self) @@ -36,12 +46,43 @@ commander.register('greenhouse', function(args, sinks) end self.sink:write(buffer) end + function gh:input(c) + -- command handling + if c == ':' and not command then + command = true + end + if c == 'Escape' then + command = false + buffer = '' + goto update + elseif c == 'Backspace' then + buffer = buffer:sub(0, -2) + goto update + end + + if command then + buffer = buffer .. c + end + + ::update:: + gh:update() + end gh:resize() gh:keybind('Enter', function(self) if self.isToc then self:jump(self.tocPageIdx) self:toc(true) + else + if buffer:len() < 2 then return end + + local splitBuf = string.split(buffer, " ") + local command = commands[splitBuf[1]:sub(2)] + if command then + table.remove(splitBuf, 1) + command(splitBuf) + end + self:update() end end) diff --git a/nature/greenhouse/init.lua b/nature/greenhouse/init.lua index 3995bef..2e2d4d1 100644 --- a/nature/greenhouse/init.lua +++ b/nature/greenhouse/init.lua @@ -176,6 +176,9 @@ function Greenhouse:toc(toggle) self:draw() end +function Greenhouse:input(char) +end + function Greenhouse:initUi() local ansikit = require 'ansikit' local bait = require 'bait' @@ -201,12 +204,14 @@ function Greenhouse:initUi() hilbish.goro(function() while not done do local c = read() - if c == 'Ctrl-D' then + self:keybind('Ctrl-D', function() done = true - end + end) if self.keybinds[c] then self.keybinds[c](self) + else + self:input(c) end --[[ diff --git a/readline/codes.go b/readline/codes.go index 9815994..dd8495d 100644 --- a/readline/codes.go +++ b/readline/codes.go @@ -188,5 +188,5 @@ func (rl *Instance) ReadChar() string { } } - return "???" + return s }