AdventurousMR

.programs

Dec 28th, 2020 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 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.  
  28.  
  29. term.clear()
  30. local function drawFrontend()
  31.         printCentered(math.floor(h/2) - 3, "")
  32.     printCentered(math.floor(h/2) - 2, "Programs")
  33.         printCentered(math.floor(h/2) - 1, "")
  34.     printCentered(math.floor(h/2) + 0, ((nOption == 1) and "[ Screens ]") or "Screens" )
  35.         printCentered(math.floor(h/2) + 1, "")
  36.     printCentered(math.floor(h/2) + 2, ((nOption == 2) and "[ Test ]") or "Test" )
  37.         printCentered(math.floor(h/2) + 3, "")
  38.     printCentered(math.floor(h/2) + 4, ((nOption == 3) and "[ Back ]") or "Back" )
  39. end
  40.  
  41. drawMenu()
  42. drawFrontend()
  43.  
  44. while true do
  45.     local e,p = os.pullEvent()
  46.         if e == "key" then
  47.             local key = p
  48.             if  key == 17 or key == 200 then
  49.                
  50.                 if nOption > 1 then
  51.                     nOption = nOption -1
  52.                     drawMenu()
  53.                     drawFrontend()
  54.                     end
  55.                 elseif key == 31 or key == 208 then
  56.                     if nOption < 3 then
  57.                     nOption = nOption + 1
  58.                     drawMenu()
  59.                     drawFrontend()
  60.                     end
  61.  
  62.             elseif key == 28 then
  63.                 break
  64.                 end
  65.             end
  66.         end
  67. term.clear()
  68.  
  69. if nOption == 1 then
  70.     shell.run(".screens")
  71. elseif nOption == 2 then
  72.     shell.run(".Test")
  73. else
  74.     shell.run(".menu")
  75. end
Add Comment
Please, Sign In to add comment