Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oldt=term
- local term=setmetatable({},{__index=oldt})
- term.old=oldt
- local record={}
- local tcols={}
- local tback={}
- local tsym={w=1,o=2,m=4,B=8,y=16,l=32,P=64,g=128,G=256,c=512,p=1024,b=2048,z=4096,r=8192,R=16384,a=32768}
- local tC=colors.white
- term.setTextColor=function(col)
- tC=col
- return oldt.setTextColor(col)
- end
- term.setTextColour=function(col)
- tC=col
- return oldt.setTextColour(col)
- end
- term.getTextColor=function()
- return tC
- end
- local bC=colors.black
- term.setBackgroundColor=function(col)
- bC=col
- return oldt.setBackgroundColor(col)
- end
- term.setBackgroundColour=function(col)
- bC=col
- return oldt.setBackgroundColour(col)
- end
- term.getBackgroundColor=function()
- return bC
- end
- term.write=function(tex)
- local pos={term.getCursorPos()}
- local size={term.getSize()}
- local tS="w"
- local bS="a"
- for k,v in pairs(tsym) do
- if v==term.getTextColor() then tS=k end
- if v==term.getBackgroundColor() then bS=k end
- end
- local function rep(t,txt)
- t[pos[2]+1]=string.sub(t[pos[2]+1] or "",1,pos[1]-1)..(pos[1]>string.len(t[pos[2]+1] or "") and string.rep(" ",pos[1]-string.len(t[pos[2]+1] or "")-1) or "")..txt..string.sub(t[pos[2]+1] or "",pos[1]+#txt)
- end
- rep(record,tex)
- rep(tcols,string.rep(tS,#tex))
- rep(tback,string.rep(bS,#tex))
- for k,v in ipairs(record) do
- if #v>pos[1] then
- record[k+1]=string.sub(v,pos[1]+1)..string.sub(record[k-1],#v+1)
- end
- end
- return oldt.write(tex)
- end
- term.getTextAt=function(x,y,len)
- if record[y+1] then
- return string.sub(record[y+1],x,x+(len or 1)-1),tsym[string.sub(tcols[y+1],x,x)],tsym[string.sub(tback[y+1],x,x)]
- else
- return nil
- end
- end
- term.scroll=function(num)
- local tnums={}
- for k,v in pairs(record) do if k>1 then table.insert(tnums,k) end end
- table.sort(tnums)
- for i=1,#tnums do
- record[tnums[i]]=record[tnums[i]+num]
- tcols[tnums[i]]=tcols[tnums[i]+num]
- tback[tnums[i]]=tback[tnums[i]+num]
- end
- return oldt.scroll(num)
- end
- term.screenShot=function()
- local tNew={{},{},{}}
- for k,v in pairs(record) do
- tNew[1][k]=v
- tNew[2][k]=tcols[k]
- tNew[3][k]=tback[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(tsym[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(tsym[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
- rawset(getfenv(),"term",term)
- rawset(_G,"term",term)
- 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,"term"))=="table" then
- rawset(t,"term",term)
- end
- until not ok
Advertisement
Add Comment
Please, Sign In to add comment