Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local explode = function(div,str,replstr,includeDiv)
- if (div=='') then return false end
- local pos,arr = 0,{}
- for st,sp in function() return string.find(str,div,pos,false) end do
- table.insert(arr,string.sub(replstr or str,pos,st-1+(includeDiv and #div or 0)))
- pos = sp + 1
- end
- table.insert(arr,string.sub(replstr or str,pos))
- return arr
- end
- blitWrap = function(text,txt,bg,noWrite)
- local words = explode(" ",text,nil,true)
- local output, lines, wordNo = {{}}, 0, 1
- local scr_x, scr_y = term.getSize()
- local cx,cy
- local startX,startY = term.getCursorPos()
- for a = 1, #text do
- cx,cy = term.getCursorPos()
- if text:sub(a,a) == " " and text:sub(a-1,a-1) ~= " " and a > 1 then
- wordNo = wordNo + 1
- if cx + #words[wordNo] > scr_x then
- term.setCursorPos(1,cy+1)
- lines = lines + 1
- output[lines+1] = {}
- end
- end
- cx,cy = term.getCursorPos()
- if text:sub(a,a) == "\n" then
- term.setCursorPos(1,cy+1)
- lines = lines + 1
- output[lines+1] = {}
- elseif not (cx == 1 and text:sub(a,a) == " ") then
- if noWrite == true then
- term.setCursorPos(cx+1,cy)
- else
- term.blit(text:sub(a,a),txt:sub(a,a),bg:sub(a,a))
- end
- output[lines+1] = {
- (output[lines+1][1] or "")..text:sub(a,a),
- (output[lines+1][2] or "")..txt:sub(a,a),
- (output[lines+1][3] or "")..bg:sub(a,a)
- }
- end
- if cx > scr_x then
- term.setCursorPos(1,cy+1)
- lines = lines + 1
- output[lines+1] = {}
- end
- end
- if noWrite then
- term.setCursorPos(startX,startY)
- end
- return lines, output
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement