atlasim

CatOS RECOVERY MODE

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