Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function overwrite(sName,replacement)
- rawset(getfenv(),sName,replacement)
- rawset(_G,sName,replacement)
- local cur=0
- repeat
- cur=cur+1
- local ok,t=pcall(function() return getfenv(cur) end)
- if ok and type(t)=="table" and type(rawget(t,sName))=="table" then
- rawset(t,sName,replacement)
- end
- until not ok
- end
- local oldTerm=term
- local term=setmetatable({},{__index=oldTerm})
- term.old=oldTerm
- local tCharacterRecord={}
- local tTextColorRecord={}
- local tBackgroundColorRecord={}
- local tColorShortHand={w=colors.white,o=colors.orange,m=colors.magenta,B=colors.lightBlue,y=colors.yellow,l=colors.lime,P=colors.pink,g=colors.gray,G=colors.lightGray,c=colors.cyan,p=colors.purple,b=colors.blue,z=colors.green,r=colors.red,a=colors.black}
- local iTextColor=colors.white
- term.setTextColor=function(iColor)
- iTextColor=iColor
- return oldTerm.setTextColor(iColor)
- end
- term.setTextColour=function(iColor)
- iTextColor=iColor
- return oldTerm.setTextColour(iColor)
- end
- term.getTextColor=function()
- return iTextColor
- end
- local iBackgroundColor=colors.black
- term.setBackgroundColor=function(iColor)
- iBackgroundColor=iColor
- return oldTerm.setBackgroundColor(iColor)
- end
- term.setBackgroundColor=function(iColor)
- iBackgroundColor=iColor
- return oldTerm.setBackgroundColor(iColor)
- end
- term.getBackgroundColor=function()
- return iBackgroundColor
- end
- term.write=function(sText)
- local CursorPosition={term.getCursorPos()}
- local TextColorShorthand="w"
- local backgroundColorShorthand="a"
- for k,v in pairs(tColorShortHand) do
- if v==term.getTextColor() then TextColorShorthand=k end
- if v==term.getBackgroundColor() then backgroundColorShorthand=k end
- end
- local function replaceLine(tRecord,sAddText)
- tRecord[CursorPosition[2]+1]=string.sub(tRecord[CursorPosition[2]+1] or "",1,CursorPosition[1]-1)..(CursorPosition[1]>string.len(tRecord[CursorPosition[2]+1] or "") and string.rep(" ",CursorPosition[1]-string.len(tRecord[CursorPosition[2]+1] or "")-1) or "")..sAddText..string.sub(tRecord[CursorPosition[2]+1] or "",CursorPosition[1]+#sAddText)
- end
- replaceLine(tCharacterRecord,sText)
- replaceLine(tTextColorRecord,string.rep(TextColorShorthand,#sText))
- replaceLine(tBackgroundColorRecord,string.rep(backgroundColorShorthand,#sText))
- for k,v in ipairs(tCharacterRecord) do
- if #v>CursorPosition[1] then
- tCharacterRecord[k+1]=string.sub(v,CursorPosition[1]+1)..string.sub(tCharacterRecord[k-1],#v+1)
- end
- end
- return oldTerm.write(sText)
- end
- term.getTextAt=function(x,y,iLength)
- if tCharacterRecord[y+1] then
- return string.sub(tCharacterRecord[y+1],x,x+(iLength or 1)-1),tColorShortHand[string.sub(tTextColorRecord[y+1],x,x)],tColorShortHand[string.sub(tBackgroundColorRecord[y+1],x,x)]
- else
- return nil
- end
- end
- term.screenShot=function()
- local tNew={{},{},{}}
- for k,v in pairs(tCharacterRecord) do
- tNew[1][k]=v
- tNew[2][k]=tTextColorRecord[k]
- tNew[3][k]=tBackgroundColorRecord[k]
- end
- return unpack(tNew)
- end
- term.loadScreen=function(t,t2,t3)
- for k,v in pairs(t) do
- term.setCursorPos(1,k)
- for i=1,#v do
- if type(t2)=="table" then
- term.setTextColor(tColorShortHand[string.sub(t2[k],i,i)])
- elseif type(t2)=="number" and i==1 then
- term.setTextColor(t2)
- end
- if type(t3)=="table" then
- term.setBackgroundColor(tColorShortHand[string.sub(t3[k],i,i)])
- elseif type(t3)=="number" and i==1 then
- term.setTextColor(t3)
- end
- write(string.sub(v,i,i))
- end
- end
- end
- term.clear=function()
- tCharacterRecord={}
- tTextColorRecord={}
- tBackgroundColorRecord={}
- return oldTerm.clear()
- end
- term.scroll=function(num)
- for k,v in pairs(tCharacterRecord) do
- if type(k)=="number" and type(num)=="number" and k-num>1 then
- tCharacterRecord[k-num]=v
- tTextColorRecord[k-num]=tTextColorRecord[k]
- tBackgroundColorRecord[k-num]=tBackgroundColorRecord[k]
- end
- end
- return oldTerm.scroll(num)
- end
- overwrite("term",term)
Advertisement
Add Comment
Please, Sign In to add comment