mirror of https://github.com/Hilbis/Hilbish
fix(nature/greenhouse): handle raw mode and term resize
parent
e368ba3e0a
commit
bb9a6fe39e
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue