BeastmodeJD

Computercraft_Programs_SampleOS

Dec 24th, 2019
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  4.  
  5. function printCentered( y,s )
  6. local x = math.floor((w - string.len(s)) / 2)
  7. term.setCursorPos(x,y)
  8. term.clearLine()
  9. term.write( s )
  10. end
  11.  
  12. local nOption = 1
  13.  
  14. local function drawMenu()
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. term.write("Impending OS Alpha // ")
  18. term.setCursorPos(1,2)
  19. shell.run("id")
  20.  
  21. term.setCursorPos(w-11,1)
  22. if nOption == 1 then
  23. term.write("Email")
  24. --elseif nOption == 2 then
  25. -- term.write("")
  26. --elseif nOption == 3 then
  27. -- term.write("")
  28. elseif nOption == 4 then
  29. term.write("Back)
  30. else
  31. end
  32.  
  33. end
  34.  
  35. --GUI
  36. term.clear()
  37. local function drawFrontend()
  38. printCentered( math.floor(h/2) - 3, "")
  39. printCentered( math.floor(h/2) - 2, "Start Menu" )
  40. printCentered( math.floor(h/2) - 1, "")
  41. printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Email ]") or "Email" )
  42. --printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs" )
  43. --printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
  44. printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Back]") or " Back" )
  45. printCentered( math.floor(h/2) + 4, "")
  46. end
  47.  
  48. --Display
  49. drawMenu()
  50. drawFrontend()
  51.  
  52. while true do
  53. local e,p = os.pullEvent()
  54. if e == "key" then
  55. local key = p
  56. if key == 17 or key == 200 then
  57.  
  58. if nOption > 1 then
  59. nOption = nOption - 1
  60. drawMenu()
  61. drawFrontend()
  62. end
  63. elseif key == 31 or key == 208 then
  64. if nOption < 4 then
  65. nOption = nOption + 1
  66. drawMenu()
  67. drawFrontend()
  68. end
  69. elseif key == 28 then
  70. --End should not be here!!
  71. break
  72. end --End should be here!!
  73. end
  74. end
  75. term.clear()
  76.  
  77. --Conditions
  78. if nOption == 1 then
  79. shell.run("os/programs/eMail")
  80. --elseif nOption == 2 then
  81. --shell.run("ios/.programs")
  82. --elseif nOption == 3 then
  83. --os.shutdown()
  84. else
  85. shell.run("os/menu")
  86. end
Advertisement
Add Comment
Please, Sign In to add comment