Advertisement
LDDestroier

BlitWrap (again)

Jun 20th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. local explode = function(div,str,replstr,includeDiv)
  2.     if (div=='') then return false end
  3.     local pos,arr = 0,{}
  4.     for st,sp in function() return string.find(str,div,pos,false) end do
  5.         table.insert(arr,string.sub(replstr or str,pos,st-1+(includeDiv and #div or 0)))
  6.         pos = sp + 1
  7.     end
  8.     table.insert(arr,string.sub(replstr or str,pos))
  9.     return arr
  10. end
  11.  
  12. blitWrap = function(char, text, back, noWrite)
  13.     local cWords = explode(" ",char,nil, true)
  14.     local tWords = explode(" ",char,text,true)
  15.     local bWords = explode(" ",char,back,true)
  16.     local ox,oy = term.getCursorPos()
  17.     local cx,cy,ty = ox,oy,1
  18.     local scr_x, scr_y = term.getSize()
  19.     local output = {}
  20.     for a = 1, #cWords do
  21.         if ((cx + #cWords[a]) > scr_x) then
  22.             cx = 1
  23.             if (cy == scr_y) then
  24.                 term.scroll(1)
  25.             end
  26.             cy = math.min(cy+1, scr_y)
  27.             ty = ty + 1
  28.         end
  29.         if not noWrite then
  30.             term.setCursorPos(cx,cy)
  31.             term.blit(cWords[a],tWords[a],bWords[a])
  32.         end
  33.         cx = cx + #cWords[a]
  34.         output[ty] = output[ty] or {"","",""}
  35.         output[ty][1] = output[ty][1]..cWords[a]
  36.         output[ty][2] = output[ty][2]..tWords[a]
  37.         output[ty][3] = output[ty][3]..bWords[a]
  38.     end
  39.     return output
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement