DRULES679

aetnaosmenu

Oct 24th, 2023 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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("AetnaOS Alpha // ")
  18.     term.setCursorPos(1,2)
  19.     shell.run("id")
  20.     term.setCursorPos(w-11,1)
  21.  
  22.     if nOption == 1 then
  23.         local optionName = "Command"
  24.         term.setCursorPos(w - string.len(optionName),1)
  25.         term.write(optionName)
  26.     elseif nOption == 2 then
  27.         local optionName = "Programs"
  28.         term.setCursorPos(w - string.len(optionName),1)
  29.         term.write(optionName)
  30.     elseif nOption == 3 then
  31.         local optionName = "Shutdown"
  32.         term.setCursorPos(w - string.len(optionName),1)
  33.         term.write(optionName)
  34.     elseif nOption == 4 then
  35.         local optionName = "Uninstall"
  36.         term.setCursorPos(w - string.len(optionName),1)
  37.         term.write(optionName)
  38.     end
  39.  end
  40.  
  41. --GUI
  42. term.clear()
  43. local function drawFrontend()
  44.    printCentered( math.floor(h/2) - 3, "")
  45.    printCentered( math.floor(h/2) - 2, "Start Menu" )
  46.    printCentered( math.floor(h/2) - 1, "")
  47.    printCentered( math.floor(h/2) + 0, ((nOption == 1) and "-> Command ") or "Command " )
  48.    printCentered( math.floor(h/2) + 1, ((nOption == 2) and "-> Programs ") or "Programs" )
  49.    printCentered( math.floor(h/2) + 2, ((nOption == 3) and "-> Shutdown") or "Shutdown" )
  50.    printCentered( math.floor(h/2) + 3, ((nOption == 4) and "-> Uninstall") or " Uninstall" )
  51.    printCentered( math.floor(h/2) + 4, "")
  52. end
  53.  
  54. --Display
  55. drawMenu()
  56. drawFrontend()
  57.  
  58. while true do
  59.     local e,p = os.pullEvent()
  60.     if e == "key" then
  61.          local key = p
  62.         if key == keys.up then
  63.             if nOption > 1 then
  64.                 nOption = nOption - 1
  65.                 drawMenu()
  66.                 drawFrontend()
  67.             end
  68.         elseif key == keys.down then
  69.             if nOption < 4 then
  70.                 nOption = nOption + 1
  71.                 drawMenu()
  72.                 drawFrontend()
  73.             end
  74.         elseif key == keys.enter then
  75.             if nOption  == 1 then
  76.                     shell.run("command")
  77.                 elseif nOption == 2 then
  78.                     shell.run("osprogramlist")
  79.                 elseif nOption == 3 then
  80.                     os.shutdown()
  81.                 else
  82.                     shell.run("delete osprogramlist")
  83.                     shell.run("delete osmenu")
  84.                     shell.run("delete startup")
  85.                     term.clear()
  86.                     term.setCursorPos(1,1)
  87.                     print("AetnaOS Uninstalled")
  88.                     term.setCursorPos(1,2)
  89.                     return
  90.             end
  91.         end
  92.     end
  93. end
  94. term.clear()
Advertisement
Add Comment
Please, Sign In to add comment