11local tHex = require (" tHex" )
2+ local utils = require (" utils" )
3+ local split = utils .splitString
24local sub ,rep = string.sub ,string.rep
35
46return function (drawTerm )
@@ -40,27 +42,33 @@ return function(drawTerm)
4042 if # t == # fg and # t == # bg then
4143 if y >= 1 and y <= height then
4244 if x + # t > 0 and x <= width then
43- local startN = x < 1 and 1 - x + 1 or 1
44- local endN = x + # t > width and width - x + 1 or # t
45-
45+ local newCacheT , newCacheFG , newCacheBG
4646 local oldCacheT , oldCacheFG , oldCacheBG = cacheT [y ], cacheFG [y ], cacheBG [y ]
47-
48- local newCacheT = sub (oldCacheT , 1 , x - 1 ) .. sub (t , startN , endN )
49- local newCacheFG = sub (oldCacheFG , 1 , x - 1 ) .. sub (fg , startN , endN )
50- local newCacheBG = sub (oldCacheBG , 1 , x - 1 ) .. sub (bg , startN , endN )
51-
47+ local startN , endN = 1 , # t
48+
49+ if x < 1 then
50+ startN = 1 - x + 1
51+ endN = width - x + 1
52+ elseif x + # t > width then
53+ endN = width - x + 1
54+ end
55+
56+ newCacheT = sub (oldCacheT , 1 , x - 1 ) .. sub (t , startN , endN )
57+ newCacheFG = sub (oldCacheFG , 1 , x - 1 ) .. sub (fg , startN , endN )
58+ newCacheBG = sub (oldCacheBG , 1 , x - 1 ) .. sub (bg , startN , endN )
59+
5260 if x + # t <= width then
5361 newCacheT = newCacheT .. sub (oldCacheT , x + # t , width )
5462 newCacheFG = newCacheFG .. sub (oldCacheFG , x + # t , width )
5563 newCacheBG = newCacheBG .. sub (oldCacheBG , x + # t , width )
5664 end
57-
65+
5866 cacheT [y ], cacheFG [y ], cacheBG [y ] = newCacheT ,newCacheFG ,newCacheBG
5967 end
6068 end
6169 end
6270 end
63-
71+
6472 local function setText (x , y , t )
6573 if y >= 1 and y <= height then
6674 if x + # t > 0 and x <= width then
@@ -86,7 +94,7 @@ return function(drawTerm)
8694 end
8795 end
8896
89- local function setBg (x , y , bg )
97+ local function setBG (x , y , bg )
9098 if y >= 1 and y <= height then
9199 if x + # bg > 0 and x <= width then
92100 local newCacheBG
@@ -111,7 +119,7 @@ return function(drawTerm)
111119 end
112120 end
113121
114- local function setFg (x , y , fg )
122+ local function setFG (x , y , fg )
115123 if y >= 1 and y <= height then
116124 if x + # fg > 0 and x <= width then
117125 local newCacheFG
@@ -136,6 +144,32 @@ return function(drawTerm)
136144 end
137145 end
138146
147+ --[[
148+ local function setText(x, y, text)
149+ if (y >= 1) and (y <= height) then
150+ local emptyLine = rep(" ", #text)
151+ blit(x, y, text, emptyLine, emptyLine)
152+ end
153+ end
154+
155+ local function setFG(x, y, colorStr)
156+ if (y >= 1) and (y <= height) then
157+ local w = #colorStr
158+ local emptyLine = rep(" ", w)
159+ local text = sub(cacheT[y], x, w)
160+ blit(x, y, text, colorStr, emptyLine)
161+ end
162+ end
163+
164+ local function setBG(x, y, colorStr)
165+ if (y >= 1) and (y <= height) then
166+ local w = #colorStr
167+ local emptyLine = rep(" ", w)
168+ local text = sub(cacheT[y], x, w)
169+ blit(x, y, text, emptyLine, colorStr)
170+ end
171+ end]]
172+
139173 local drawHelper = {
140174 setSize = function (w , h )
141175 width , height = w , h
@@ -146,17 +180,17 @@ return function(drawTerm)
146180 mirrorTerm = mirror
147181 end ,
148182
149- setBg = function (x , y , colorStr )
150- setBg (x , y , colorStr )
183+ setBG = function (x , y , colorStr )
184+ setBG (x , y , colorStr )
151185 end ,
152186
153187 setText = function (x , y , text )
154188 setText (x , y , text )
155189 end ,
156190
157- setFg = function (x , y , colorStr )
158- setFg (x , y , colorStr )
159- end ,
191+ setFG = function (x , y , colorStr )
192+ setFG (x , y , colorStr )
193+ end ;
160194
161195 blit = function (x , y , t , fg , bg )
162196 blit (x , y , t , fg , bg )
@@ -165,13 +199,13 @@ return function(drawTerm)
165199 drawBackgroundBox = function (x , y , width , height , bgCol )
166200 local colorStr = rep (tHex [bgCol ], width )
167201 for n = 1 , height do
168- setBg (x , y + (n - 1 ), colorStr )
202+ setBG (x , y + (n - 1 ), colorStr )
169203 end
170204 end ,
171205 drawForegroundBox = function (x , y , width , height , fgCol )
172206 local colorStr = rep (tHex [fgCol ], width )
173207 for n = 1 , height do
174- setFg (x , y + (n - 1 ), colorStr )
208+ setFG (x , y + (n - 1 ), colorStr )
175209 end
176210 end ,
177211 drawTextBox = function (x , y , width , height , symbol )
0 commit comments