Advertisement
dragon_lord1

.menu

Mar 29th, 2024 (edited)
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | Gaming | 0 0
  1. -- save file as .menu in root
  2. -- most of the code from Homelab youtube tut 1
  3. os.pullEvent = os.pullEventRaw -- prevents CTRL + T bypass
  4. local w,h = term.getSize()
  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. term.setTextColour(colours.orange)
  12. local nOption = 1
  13. local function drawMenu()
  14.         term.clear()
  15.         term.setCursorPos(1,1)
  16.         term.write("Nexus OS")
  17.         term.setCursorPos(w-8,1)
  18.         if nOption == 1 then
  19.             term.write("Root")
  20.         elseif nOption == 2 then
  21.             term.write("Programs")
  22.         elseif nOption == 3 then
  23.             term.write("Shutdown")
  24.         elseif nOption == 4 then
  25.             term.setTextColour(colours.red)
  26.             term.write("Terminate System")
  27.             term.setTextColour(colours.orange)
  28.         else
  29.             end
  30. end        
  31.  
  32. --GUI
  33. term.clear()
  34. local function drawFrontend()
  35.         printCentered(math.floor(h/2) - 3, "")
  36.         printCentered(math.floor(h/2) - 2, "Start Menu")
  37.         printCentered(math.floor(h/2) - 1, "")
  38.         printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Root ]") or "Root")
  39.         printCentered(math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs")
  40.         printCentered(math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown")
  41.         term.setTextColour(colours.red)
  42.         printCentered(math.floor(h/2) + 3, ((nOption == 4) and "[ Terminate System ]") or "Terminate System")
  43.         term.setTextColour(colours.orange)
  44. end
  45. --Display
  46. drawMenu()
  47. drawFrontend()
  48.  
  49. while true do
  50.     local e,p = os.pullEvent()
  51.         if e == "key" then
  52.             local key = p
  53.             if key == keys.up and nOption > 1 then
  54.                 nOption = nOption - 1
  55.                 drawMenu()
  56.                 drawFrontend()
  57.             elseif key == keys.down and nOption < 4 then
  58.                 nOption = nOption + 1
  59.                 drawMenu()
  60.                 drawFrontend()
  61.             elseif key == keys.enter then
  62.                 break
  63.             end
  64.         end
  65.     end
  66.  
  67. --Conditions
  68. if nOption == 1 then
  69.    shell.run("os/.root")
  70. elseif nOption == 2 then
  71.    shell.run("os/.programs")
  72. elseif nOption == 3 then
  73.    os.shutdown()
  74. elseif nOption == 4 then
  75.    shell.run("os/terminate")
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement