@@ -44,6 +44,21 @@ function Greenhouse:updateCurrentPage(text)
44
44
page :setText (text )
45
45
end
46
46
47
+ local function sub (str , limit )
48
+ local overhead = 0
49
+ local function addOverhead (s )
50
+ overhead = overhead + string.len (s )
51
+ end
52
+
53
+ local s = str :gsub (' \x1b %[%d+;%d+;%d+;%d+;%d+%w' , addOverhead )
54
+ :gsub (' \x1b %[%d+;%d+;%d+;%d+%w' , addOverhead )
55
+ :gsub (' \x1b %[%d+;%d+;%d+%w' ,addOverhead )
56
+ :gsub (' \x1b %[%d+;%d+%w' , addOverhead )
57
+ :gsub (' \x1b %[%d+%w' , addOverhead )
58
+
59
+ return s :sub (0 , limit + overhead )
60
+ end
61
+
47
62
function Greenhouse :draw ()
48
63
local workingPage = self .pages [self .curPage ]
49
64
local offset = self .offset
@@ -56,10 +71,9 @@ function Greenhouse:draw()
56
71
self .sink :write (ansikit .getCSI (self .start .. ' ;1' , ' H' ))
57
72
self .sink :write (ansikit .getCSI (2 , ' J' ))
58
73
59
- -- the -2 negate is for the command and status line
60
- for i = offset , offset + (self .region .height - self .start ) do
74
+ for i = offset , offset + (self .region .height - 1 ) do
61
75
if i > # lines then break end
62
- self .sink :writeln (' \r ' .. lines [i ]:gsub (' \t ' , ' ' ): sub ( 0 , self .region .width - 2 ))
76
+ self .sink :writeln (' \r ' .. sub ( lines [i ]:gsub (' \t ' , ' ' ), self .region .width - 2 ))
63
77
end
64
78
self .sink :write ' \r '
65
79
self :render ()
@@ -82,7 +96,7 @@ function Greenhouse:scroll(direction)
82
96
83
97
local oldOffset = self .offset
84
98
if direction == ' down' then
85
- self .offset = math.min (self .offset + 1 , # lines )
99
+ self .offset = math.min (self .offset + 1 , math.max ( 1 , # lines - self . region . height + 1 ) )
86
100
elseif direction == ' up' then
87
101
self .offset = math.max (self .offset - 1 , 1 )
88
102
end
0 commit comments