Advertisement
Snaxiiii

Menu

Feb 13th, 2025 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 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.     local options = { "Command", "Programs", "Shutdown", "Uninstall" }
  23.     term.write(options[nOption] or "")
  24. end
  25.  
  26. local function drawFrontend()
  27.     printCentered(math.floor(h / 2) - 3, "")
  28.     printCentered(math.floor(h / 2) - 2, "Start Menu")
  29.     printCentered(math.floor(h / 2) - 1, "")
  30.     printCentered(math.floor(h / 2) + 0, (nOption == 1 and "[ Command  ]") or "Command")
  31.     printCentered(math.floor(h / 2) + 1, (nOption == 2 and "[ Programs ]") or "Programs")
  32.     printCentered(math.floor(h / 2) + 2, (nOption == 3 and "[ Shutdown ]") or "Shutdown")
  33.     printCentered(math.floor(h / 2) + 3, (nOption == 4 and "[ Uninstall ]") or "Uninstall")
  34.     printCentered(math.floor(h / 2) + 4, "")
  35. end
  36.  
  37. -- Display
  38. drawMenu()
  39. drawFrontend()
  40.  
  41. while true do
  42.     local event, key = os.pullEvent("key")
  43.  
  44.     if key == keys.z or key == keys.up then -- "Z" instead of "W" for QWERTZ
  45.         if nOption > 1 then
  46.             nOption = nOption - 1
  47.             drawMenu()
  48.             drawFrontend()
  49.         end
  50.     elseif key == keys.s or key == keys.down then
  51.         if nOption < 4 then
  52.             nOption = nOption + 1
  53.             drawMenu()
  54.             drawFrontend()
  55.         end
  56.     elseif key == keys.enter then
  57.         break
  58.     end
  59. end
  60.  
  61. term.clear()
  62.  
  63. -- Conditions for selection
  64. if nOption == 1 then
  65.     shell.run("ios/.command")
  66. elseif nOption == 2 then
  67.     shell.run("ios/.programs")
  68. elseif nOption == 3 then
  69.     os.shutdown()
  70. elseif nOption == 4 then
  71.     shell.run("ios/.UninstallDialog")
  72. end
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement