Advertisement
AdventurousMR

.menu

Dec 27th, 2020 (edited)
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 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. function printLeft (y,s)
  13.     local x = math.floor((w - string.len(s)) / 2)
  14.     term.setCursorPos(x - 18 , y)
  15.     term.clearLine()
  16.     term.write(s)
  17. end
  18.  
  19. local nOption = 1
  20.  
  21. local function drawMenu()
  22.     term.clear()
  23.     term.setCursorPos(1,1)
  24.     term.write("Atlantica OS v1.1")
  25. end
  26.  
  27. term.clear()
  28. local function drawFrontend()
  29.         printCentered(math.floor(h/2) - 3, "")
  30.     printCentered(math.floor(h/2) - 2, "Desktop")  
  31.         printCentered(math.floor(h/2) - 1, "")
  32.     printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Command ]") or "Command" )
  33.         printCentered(math.floor(h/2) + 1, "")
  34.     printCentered(math.floor(h/2) + 2, ((nOption == 2) and "[ Programs ]") or "Programs" )
  35.         printCentered(math.floor(h/2) + 3, "")
  36.     printCentered(math.floor(h/2) + 4, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
  37. end
  38.  
  39. drawMenu()
  40. drawFrontend()
  41.  
  42. while true do
  43.     local e,p = os.pullEvent()
  44.         if e == "key" then
  45.             local key = p
  46.             if  key == 17 or key == 200 then
  47.                
  48.                 if nOption > 1 then
  49.                     nOption = nOption -1
  50.                     drawMenu()
  51.                     drawFrontend()
  52.                     end
  53.                 elseif key == 31 or key == 208 then
  54.                     if nOption < 3 then
  55.                     nOption = nOption + 1
  56.                     drawMenu()
  57.                     drawFrontend()
  58.                     end
  59.  
  60.             elseif key == 28 then
  61.                 break
  62.                 end
  63.             end
  64.         end
  65. term.clear()
  66.  
  67. if nOption == 1 then
  68.     shell.run(".command")
  69. elseif nOption == 2 then
  70.     shell.run(".programs")
  71. else
  72.     os.shutdown()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement