DYankee

Menu

Mar 18th, 2022 (edited)
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. V = settings.get("Version")
  2. local w,h = term.getSize()
  3.  
  4.  
  5. -- print centered on x axis
  6. function printCentered(y,s)
  7.    local x = math.floor((w - string.len(s)) /2)
  8.    term.setCursorPos(x,y)
  9.    term.clearLine()
  10.    term.write(s)
  11. end
  12.  
  13. --Draw menu function
  14. local mOption = 1
  15. local function drawMenu()
  16.     term.clear()
  17.     printCentered(1,"Lapis OS " .. V )
  18.  
  19.     term.setCursorPos(w-11,1)
  20.     if mOption == 1 then
  21.         term.write("Command Line")
  22.     elseif mOption == 2 then
  23.         term.write("Programs")
  24.     elseif mOption == 3 then
  25.         term.write("Shutdown")
  26.     else
  27.     end
  28. end
  29.  
  30. --GUI
  31. local function drawFrontend()
  32.     term.clear()
  33.     printCentered(math.floor(h/2) - 3, "")
  34.     printCentered(math.floor(h/2) - 2, "Start Menu")
  35.     printCentered(math.floor(h/2) - 1, "")
  36.     printCentered(math.floor(h/2) + 0, ((mOption == 1 and "[ Command Line ]") or " Command Line " ))
  37.     printCentered(math.floor(h/2) + 1, ((mOption == 2 and "[ Programs     ]") or " Programs     " ))
  38.     printCentered(math.floor(h/2) + 2, ((mOption == 3 and "[ Shutdown     ]") or " Shutdown     " ))
  39. end
  40.  
  41. --Display
  42. drawMenu()
  43. drawFrontend()
  44.  
  45.  
  46. while true do
  47.     local event, key = os.pullEvent()
  48.     if event == "key" then
  49.         if key == 265 or key == 87 then
  50.             if mOption > 1 then
  51.                 mOption = mOption - 1
  52.                 drawMenu()
  53.                 drawFrontend()
  54.             end
  55.         elseif key == 264 or key == 83 then
  56.             if mOption < 3 then
  57.                 mOption = mOption + 1
  58.                 drawMenu()
  59.                 drawFrontend()
  60.             end
  61.         elseif key == 257 then
  62.             break
  63.         end
  64.     end
  65. end
  66.  
  67. if mOption == 1 then
  68.     shell.run("/os/command")
  69. elseif mOption == 2 then
  70.     shell.run("/os/programMenu")
  71. elseif mOption == 3 then
  72.     os.shutdown()
  73. else
  74. end
Add Comment
Please, Sign In to add comment