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))
|
sinks.err:writeln(string.format('could not open file %s', fname))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local gh = Greenhouse(sinks.out)
|
||||||
|
gh:setText(f:read '*a')
|
||||||
|
|
||||||
bait.catch('signal.sigint', function()
|
bait.catch('signal.sigint', function()
|
||||||
done = true
|
done = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local gh = Greenhouse(sinks.out)
|
bait.catch('signal.resize', function()
|
||||||
gh:setText(f:read '*a')
|
gh:update()
|
||||||
|
end)
|
||||||
|
|
||||||
ansikit.screenAlt()
|
ansikit.screenAlt()
|
||||||
ansikit.clear(true)
|
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
|
-- 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.
|
-- job and then the user can draw whatever outside it.
|
||||||
-- This reduces code duplication for the message viewer
|
-- 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
|
for i = self.offset, self.offset + (self.region.height - self.start) - 1 do
|
||||||
self.sink:write(ansikit.getCSI(2, 'K'))
|
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
|
end
|
||||||
|
self.sink:write '\r'
|
||||||
end
|
end
|
||||||
|
|
||||||
function Greenhouse:scroll(direction)
|
function Greenhouse:scroll(direction)
|
||||||
|
@ -39,6 +40,12 @@ function Greenhouse:scroll(direction)
|
||||||
elseif direction == 'up' then
|
elseif direction == 'up' then
|
||||||
self.offset = math.max(self.offset - 1, 1)
|
self.offset = math.max(self.offset - 1, 1)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Greenhouse:update()
|
||||||
|
local size = terminal.size()
|
||||||
|
self.region = size
|
||||||
|
|
||||||
self:draw()
|
self:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue