Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lines = {}
- local curText = "";
- local w,h = term.getSize();
- function refresh()
- term.clear()
- for i=1,h-1 do
- term.setCursorPos(1,h-i)
- term.write(lines[#lines-i+1])
- end
- term.setCursorPos(1,h)
- term.write("> "..curText)
- end
- function newPrint(text)
- lines[#lines+1] = tostring(text)
- refresh()
- end
- local betterEnv = {print = newPrint}
- setmetatable(betterEnv,{__index = _G})
- function getReturn(comm)
- local func = loadstring(comm);
- setfenv(func,betterEnv)
- pcall(func)
- end
- while true do
- local name,arg1,arg2,arg3,arg4 = os.pullEvent();
- if name == "char" then
- curText = curText..arg1;
- elseif name == "key" then
- if arg1 == 14 then
- if curtext then curtText:sub(-1); end
- elseif arg1 == 28 then
- getReturn(curText)
- curText = ""
- end
- end
- refresh()
- end
Advertisement
Add Comment
Please, Sign In to add comment