Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local colors_names = { --this has been modified to use the Paint colors rather than minecraft formatting
- ["0"] = colors.white,
- ["1"] = colors.orange,
- ["2"] = colors.magenta,
- ["3"] = colors.lightBlue,
- ["4"] = colors.yellow,
- ["5"] = colors.lime,
- ["6"] = colors.pink,
- ["7"] = colors.gray,
- ["8"] = colors.lightGray,
- ["9"] = colors.cyan,
- ["a"] = colors.purple,
- ["b"] = colors.blue,
- ["c"] = colors.brown,
- ["d"] = colors.green,
- ["e"] = colors.red,
- ["f"] = colors.black,
- }
- local blit_names = {}
- for k,v in pairs(colors_names) do
- blit_names[v] = k
- end
- local function explode(div,str)
- if (div=='') then return false end
- local pos,arr = 0,{}
- for st,sp in function() return string.find(str,div,pos,true) end do
- table.insert(arr,string.sub(str,pos,st-1))
- pos = sp + 1
- end
- table.insert(arr,string.sub(str,pos))
- return arr
- end
- blitWrap = function(text,txt,bg)
- local wordNo = 1
- local words = explode(" ",text)
- local lines = 0
- local scr_x, scr_y = term.getSize()
- local cx,cy
- 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
- end
- end
- cx,cy = term.getCursorPos()
- if text:sub(a,a) == "\n" then
- term.setCursorPos(1,cy+1)
- lines = lines + 1
- elseif not (cx == 1 and text:sub(a,a) == " ") then
- term.blit(text:sub(a,a),txt:sub(a,a),bg:sub(a,a))
- end
- if cx == scr_x then
- term.setCursorPos(1,cy+1)
- lines = lines + 1
- end
- end
- return lines
- end
- local codeNames = { --shaddap
- ["r"] = "reset"
- }
- local textToBlit = function(str) --returns output for term.blit, or blitWrap, with formatting codes for color selection.
- local p = 1
- local output = ""
- local txcolorout = ""
- local bgcolorout = ""
- local txcode = "&"
- local bgcode = "~"
- local txcol = blit_names[term.getTextColor()]
- local bgcol = blit_names[term.getBackgroundColor()]
- local cx,cy
- while p <= #str do
- if str:sub(p,p) == txcode then
- if colors_names[str:sub(p+1,p+1)] then
- txcol = str:sub(p+1,p+1)
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] then
- if str:sub(p+1,p+1) == "r" then
- txcol = blit_names[term.getTextColor()]
- bgcol = blit_names[term.getBackgroundColor()]
- end
- p = p + 1
- end
- p = p + 1
- elseif str:sub(p,p) == bgcode then
- if colors_names[str:sub(p+1,p+1)] then
- bgcol = str:sub(p+1,p+1)
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] then
- if str:sub(p+1,p+1) == "r" then
- txcol = blit_names[term.getTextColor()]
- bgcol = blit_names[term.getBackgroundColor()]
- end
- p = p + 1
- end
- p = p + 1
- else
- output = output..str:sub(p,p)
- txcolorout = txcolorout..txcol
- bgcolorout = bgcolorout..bgcol
- p = p + 1
- end
- end
- return output, txcolorout, bgcolorout
- end
- writef = function(txt)
- local text, textCol, bgCol = textToBlit(txt)
- local out = blitWrap(text,textCol,bgCol)
- return out
- end
- printf = function(txt)
- return writef(tostring(txt.."\n"))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement