Creeper9207

COS:term

Feb 21st, 2015
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. --Creeper9207 Code: CyptonOS Terminal--
  2. a = { ... }
  3. running = 1
  4. startMenu = 0
  5. os.unloadAPI("/home/termapi")
  6. os.loadAPI("/home/termapi")
  7. os.unloadAPI("/home/dbapi")
  8. os.loadAPI("/home/dbapi")
  9. function ddraw()
  10. x, y = term.getCursorPos()
  11. x2, z2 = term.getSize()
  12. termapi.draw()
  13. term.setCursorPos(x, y)
  14. term.setBackgroundColor(colors.black)
  15. term.setTextColor(colors.green)
  16. end
  17. function drawMenu()
  18. x, y = term.getCursorPos()
  19. paintutils.drawFilledBox(1, 2, 7, 6, colors.lightGray)
  20. term.setTextColor(colors.white)
  21. term.setCursorPos(1, 2)
  22. term.write("[Desk]")
  23. term.setCursorPos(1, 3)
  24. term.write("[Files]")
  25. term.setCursorPos(1, 4)
  26. term.write("[Quest]")
  27. term.setCursorPos(1, 5)
  28. term.write("[Text]")
  29. term.setTextColor(colors.green)
  30. term.setCursorPos(x, y)
  31. end
  32. function drawRCM(x, y)
  33. paintutils.drawFilledBox(x, y, x+7, y+6, colors.lightGray)
  34. end
  35. shell.setDir("home")
  36. shell.setAlias("nano", "/home/nano")
  37. term.setCursorPos(1, 19)
  38. if fs.exists("/.termdata/hasran") == true then
  39. else
  40. mainsetup = { at = "null", bt = "nil", }
  41. ot = fs.open("/home/main", "w")
  42. ot.write(textutils.serialize(mainsetup))
  43. ot.flush()
  44. ot.close()
  45. term.setTextColor( colors.green )
  46. term.setCursorPos(1, 19)
  47. print("Please type a new password")
  48. io.write("> ")
  49. termapi.draw()
  50. term.setBackgroundColor( colors.black )
  51. term.setTextColor( colors.green )
  52. term.setCursorPos(3, 19)
  53. passwd = io.read()
  54. dbapi.setValue("/home/main", 2, passwd)
  55. print("Please enter a name for this computer")
  56. io.write("> ")
  57. termapi.draw()
  58. term.setTextColor(colors.green)
  59. term.setBackgroundColor( colors.black )
  60. term.setCursorPos(3, 19)
  61. cname = io.read()
  62. dbapi.setValue("/home/main", 3, cname)
  63. h = fs.open("/.termdata/hasran", "w")
  64. h.write("do not delete")
  65. h.flush()
  66. h.close()
  67. end
  68. function verify()
  69. x, y = term.getSize()
  70. term.setTextColor(colors.green)
  71. term.setCursorPos(1, y)
  72. print("Password:")
  73. io.write("> ")
  74. termapi.draw()
  75. term.setBackgroundColor( colors.black )
  76. term.setTextColor(colors.black)
  77. term.setCursorPos(3, y)
  78. password = io.read()
  79. term.setTextColor(colors.green)
  80. if password == dbapi.getValue("/home/main", 2) then
  81. else
  82. print("Incorrect, please try again")
  83. verify()
  84. end
  85. end
  86. term.setBackgroundColor(colors.black)
  87. verify()
  88. shell.setAlias("term", "/home/term")
  89. function tshell()
  90. while true do
  91. termapi.draw()
  92. x, y = term.getSize()
  93. term.setTextColor(colors.green)
  94. term.setCursorPos(1, y)
  95. term.setBackgroundColor(colors.black)
  96. term.write(dbapi.getValue("/home/main", 3) .. " " .. shell.dir() .. "> ")
  97. a = io.read()
  98. tostring(a)
  99. if string.find(a, "run") then
  100. b = a:gsub("run ", "")
  101. shell.run(b)
  102. elseif string.find(a, "cd") then
  103. shell.run(a)
  104. elseif string.find(a, "dir") then
  105. shell.run(a)
  106. elseif string.find(a, "nano") then
  107. shell.run(a)
  108. elseif string.find(a, "mkdir") then
  109. shell.run(a)
  110. elseif string.find(a, "shutdown") then
  111. os.shutdown()
  112. elseif string.find(a, "reboot") then
  113. os.reboot()
  114. elseif string.find(a, "wget") then
  115. shell.run(a)
  116. elseif string.find(a, "passwd") then
  117. shell.run(a)
  118. elseif string.find(a, "label") then
  119. b = a:gsub("label ", "")
  120. dbapi.setValue("/home/main.db", 3, b)
  121. print("Computer name set to " .. b)
  122. os.reboot()
  123. elseif string.find(a, "files") then
  124. shell.run(a)
  125. elseif string.find(a, "launch") then
  126. if fs.exists("/home/apps/" .. a) then
  127. shell.run("/home/apps/" .. a)
  128. else
  129. print("App not found, type 'Apps' for a list of apps")
  130. end
  131. elseif string.find(a, "desktop") then
  132. shell.run("/home/gui/desktop")
  133. else
  134. shell.run(a)
  135. --print("unknown command or program not found, type 'help' for command list")
  136. end
  137. end
  138. end
  139. function buttons()
  140. while true do
  141. event, button, x, y = os.pullEvent()
  142. if not event == "mouse_click" then
  143. else
  144. if event then
  145. if button == 1 then
  146. if x < 7 and y == 1 then
  147. if startMenu == 0 then
  148. sleep(0.01)
  149. drawMenu()
  150. startMenu = 1
  151. else
  152. ddraw()
  153. startMenu = 0
  154. end
  155. elseif x < 7 and y == 2 and startMenu == 1 then
  156. os.reboot()
  157. elseif x < 7 and y == 3 and startMenu == 1 then
  158. os.reboot()
  159. elseif x < 7 and y == 4 and startMenu == 1 then
  160. os.reboot()
  161. elseif x < 7 and y == 5 and startMenu == 1 then
  162. os.reboot()
  163. end
  164. elseif button == 2 then
  165. if RCM == 0 then
  166. --drawRCM(x, y)
  167. RCM = 1
  168. else
  169. --draw()
  170. RCM = 0
  171. end
  172. end
  173. end
  174. end
  175. end
  176. end
  177. while true do
  178. parallel.waitForAny(tshell, buttons)
  179. end
Advertisement
Add Comment
Please, Sign In to add comment