Cobra_Tomtrein-temp-

testme

May 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. local lines = {}
  2.  
  3. local curText = "";
  4.  
  5. local w,h = term.getSize();
  6.  
  7. function refresh()
  8. term.clear()
  9. for i=1,h-1 do
  10. term.setCursorPos(1,h-i)
  11. term.write(lines[#lines-i+1])
  12. end
  13. term.setCursorPos(1,h)
  14. term.write("> "..curText)
  15. end
  16.  
  17.  
  18. function newPrint(text)
  19. lines[#lines+1] = tostring(text)
  20. refresh()
  21. end
  22.  
  23. local betterEnv = {print = newPrint}
  24.  
  25. setmetatable(betterEnv,{__index = _G})
  26.  
  27.  
  28.  
  29. function getReturn(comm)
  30. local func = loadstring(comm);
  31. setfenv(func,betterEnv)
  32. pcall(func)
  33. end
  34.  
  35.  
  36.  
  37. while true do
  38. local name,arg1,arg2,arg3,arg4 = os.pullEvent();
  39. if name == "char" then
  40. curText = curText..arg1;
  41. elseif name == "key" then
  42. if arg1 == 14 then
  43. if curtext then curtText:sub(-1); end
  44. elseif arg1 == 28 then
  45. getReturn(curText)
  46. curText = ""
  47. end
  48. end
  49. refresh()
  50. end
Advertisement
Add Comment
Please, Sign In to add comment