diff --git a/nature/commands/greenhouse.lua b/nature/commands/greenhouse.lua index 916c29a..df01196 100644 --- a/nature/commands/greenhouse.lua +++ b/nature/commands/greenhouse.lua @@ -13,12 +13,16 @@ commander.register('greenhouse', function(args, sinks) sinks.err:writeln(string.format('could not open file %s', fname)) end + local gh = Greenhouse(sinks.out) + gh:setText(f:read '*a') + bait.catch('signal.sigint', function() done = true end) - local gh = Greenhouse(sinks.out) - gh:setText(f:read '*a') + bait.catch('signal.resize', function() + gh:update() + end) ansikit.screenAlt() ansikit.clear(true) diff --git a/nature/greenhouse.lua b/nature/greenhouse.lua index 390c454..1e292e2 100644 --- a/nature/greenhouse.lua +++ b/nature/greenhouse.lua @@ -1,4 +1,4 @@ --- Greenhouse is a simple text scrolling handler for terminal program. +-- Greenhouse is a simple text scrolling handler for terminal programs. -- The idea is that it can be set a region to do its scrolling and paging -- job and then the user can draw whatever outside it. -- This reduces code duplication for the message viewer @@ -29,8 +29,9 @@ function Greenhouse:draw() for i = self.offset, self.offset + (self.region.height - self.start) - 1 do self.sink:write(ansikit.getCSI(2, 'K')) - self.sink:writeln(self.lines[i]:gsub('\t', ' '):sub(0, self.region.width - 2)) + self.sink:writeln('\r' .. self.lines[i]:gsub('\t', ' '):sub(0, self.region.width - 2)) end + self.sink:write '\r' end function Greenhouse:scroll(direction) @@ -39,6 +40,12 @@ function Greenhouse:scroll(direction) elseif direction == 'up' then self.offset = math.max(self.offset - 1, 1) end +end + +function Greenhouse:update() + local size = terminal.size() + self.region = size + self:draw() end