Advertisement
Guest User

faketerm

a guest
Mar 30th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.25 KB | None | 0 0
  1. --defaults
  2. local color = true
  3. local size_x = 51
  4. local size_y = 19
  5. local cur_x = 1
  6. local cur_y = 1
  7.  
  8. local history = {}
  9. local spill_t = {}
  10.  
  11. function table.find(t,val) for i, v in ipairs(t) do if v == val then return i end end return nil end
  12.  
  13. function write(text) if history[table.getn(history)][1]=="write" then history[table.getn(history)][1] = history[table.getn(history)][1]..text else table.insert(history,{"write",text}) end return end
  14. function clear() if history[table.getn(history)][1]=="clear" then return end table.insert(history,{"clear"}) return end
  15. function clearLine() if history[table.getn(history)][1]=="clearLine" then return end table.insert(history,{"clearLine"}) return end
  16. function getCursorPos() return cur_x,cur_y end
  17. function setCursorPos(x,y) cur_x = x cur_y = y if history[table.getn(history)][1]=="setCursorPos" then history[table.getn(history)][2],history[table.getn(history)][3] = x,y return end table.insert(history,{"setCursorPos",x,y}) return end
  18. function setCursorBlink(b) if history[table.getn(history)][1] == "setCursorBlink" then history[table.getn(history)][2] = b return end table.insert(history,{"setCursorBlink",b}) return end
  19. function isColor() return color end
  20. isColour = isColor
  21. function getSize() return size_x,size_y end
  22. function scroll(n) if history[table.getn(history)][1] == "scroll" then history[table.getn(history)][2] = history[table.getn(history)][2]+n return end table.insert(history,{"scroll",n}) return end
  23. function setTextColor(color) if history[table.getn(history)][1] == "setTextColor" then  history[table.getn(history)][2] = color return end table.insert(history,{"setTextColor",color}) return end
  24. setTextColour = setTextColor
  25. function setBackgroundColor(color) if history[table.getn(history)][1] == "setBackgroundColor" then  history[table.getn(history)][2] = color return end table.insert(history,{"setBackgroundColor",color}) return end
  26. setBackgroundColour = setBackgroundColor
  27. function setTextScale(scale) if history[table.getn(history)][1] == "setTextScale" then  history[table.getn(history)][2] = scale return end table.insert(history,{"setTextScale",scale}) return end
  28.  
  29. function newFakeTerm(col,sx,sy,cx,cy)
  30.   local ft = os.clock()
  31.   local ft_sp = {}
  32.   --spill
  33.   ft_sp["color"] = color
  34.   ft_sp["size_x"] = size_x
  35.   ft_sp["size_y"] = size_y
  36.   ft_sp["cur_x"] = cur_x
  37.   ft_sp["cur_y"] = cur_y
  38.   ft_sp["history"] = {} for _,v in ipairs(history) do table.insert(ft_sp["history"],v) end
  39.   history = {}
  40.   spill_t[ft] = ft_sp
  41.   --set new vals
  42.   if col == nil then color = true else color = col end
  43.   if sx == nil then size_x = 51 else color = sx end
  44.   if sy == nil then size_y = 19 else color = sy end
  45.   if cx == nil then cur_x = 1 else color = cx end
  46.   if cy == nil then cur_y = 1 else color = cy end
  47.   return ft
  48. end
  49.  
  50. function deleteFakeTerm(ft)
  51.   local ft_sp = spill_t[ft]
  52.   if ft_sp == nil then return end
  53.   color = ft_sp["color"]
  54.   size_x = ft_sp["size_x"]
  55.   size_y = ft_sp["size_y"]
  56.   cur_x = ft_sp["cur_x"]
  57.   cur_y = ft_sp["cur_y"]
  58.   history = {} for _,v in ipairs(ft_sp["history"]) do table.insert(history,v) end
  59.  
  60.   local ind = table.find(spill_t,ft)
  61.   if ind ~= nil then table.remove(spill_t,ind) end
  62. end
  63.  
  64. function clearHistory(ft) history = {} end
  65. function historyCopy(ft) local rval = {} for _,v in ipairs(history) do table.insert(rval, v) end return rval end
  66.  
  67. function replayHistory(historyTable, termObject)
  68.   if termObject == nil then termObject = term.current() end
  69.   for i,v in pairs(historyTable) do
  70.     if v[1] == "write" then termObject.write(v[2]) end
  71.     if v[1] == "clear" then termObject.clear() end
  72.     if v[1] == "clearLine" then termObject.clearLine() end
  73.     if v[1] == "setCursorPos" then termObject.setCursorPos(v[2],v[3]) end
  74.     if v[1] == "setCursorBlink" then termObject.setCursorBlink(v[2]) end
  75.     if v[1] == "scroll" then termObject.scroll(v[2]) end
  76.     if v[1] == "setTextColor" then termObject.setTextColor(v[2]) end
  77.     if v[1] == "setBackgroundColor" then termObject.setBackgroundColor(v[2]) end
  78.     if v[1] == "setTextScale" then termObject.setTextScale(v[2]) end
  79.   end
  80. end
  81.  
  82. function wrapTerm(termObject)
  83.   local rval = {}
  84.   rval.col = termObject.isColor()
  85.   rval.sx,rval.sy = termObject.getSize()
  86.   rval.cx,rval.cy = termObject.getCursorPos()
  87.   return rval
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement