fix(greenhouse): print contents properly

on the last line that can be displayed, don't print with a newline
this removes the space at the end
pull/240/head
sammyette 2023-07-11 22:28:11 -04:00
parent 7d0c3f3bf0
commit b9bb14497f
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 7 additions and 4 deletions

View File

@ -71,11 +71,14 @@ function Greenhouse:draw()
self.sink:write(ansikit.getCSI(self.start .. ';1', 'H')) self.sink:write(ansikit.getCSI(self.start .. ';1', 'H'))
self.sink:write(ansikit.getCSI(2, 'J')) self.sink:write(ansikit.getCSI(2, 'J'))
for i = offset, offset + (self.region.height - 1) do for i = offset, offset + self.region.height - 1 do
if i > #lines then break end if i > #lines then break end
self.sink:writeln('\r' .. sub(lines[i]:gsub('\t', ' '), self.region.width - 2))
local writer = self.sink.writeln
if i == offset + self.region.height - 1 then writer = self.sink.write end
writer(self.sink, sub(lines[i]:gsub('\t', ' '), self.region.width))
end end
self.sink:write '\r'
self:render() self:render()
end end
@ -96,7 +99,7 @@ function Greenhouse:scroll(direction)
local oldOffset = self.offset local oldOffset = self.offset
if direction == 'down' then if direction == 'down' then
self.offset = math.min(self.offset + 1, math.max(1, #lines - self.region.height + 1)) self.offset = math.min(self.offset + 1, math.max(1, #lines - self.region.height))
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