Advertisement
Guest User

faketerm

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