Advertisement
Guest User

.menu

a guest
Dec 11th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1.  
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. local w,h = term.getSize()
  5.  
  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. local nOption = 1
  14.  
  15. local function drawMenu()
  16.    term.clear()
  17.    term.setCursorPos(1,1)
  18.    term.write("lucOS v1.0")
  19. term.setCursorPos(1,2)
  20. shell.run("id")
  21.  
  22.    term.setCursorPos(w-11,1)
  23.    if nOption == 1 then
  24.    term.write("Command")
  25. elseif nOption == 2 then
  26.    term.write("Programs")
  27. elseif nOption == 3 then
  28.    term.write("Shutdown")
  29. elseif nOption == 4 then
  30.    term.write("Uninstall")
  31. else
  32. end
  33.  
  34. end
  35.  
  36. --GUI
  37. term.clear()
  38. local function drawFrontend()
  39.    printCentered( math.floor(h/2) - 3, "")
  40.    printCentered( math.floor(h/2) - 2, "Start Menu" )
  41.    printCentered( math.floor(h/2) - 1, "")
  42.    printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Command  ]") or "Command " )
  43.    printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs" )
  44.    printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
  45.    printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Uninstall]") or " Uninstall" )
  46.    printCentered( math.floor(h/2) + 4, "")
  47. end
  48.  
  49. --Display
  50. drawMenu()
  51. drawFrontend()
  52.  
  53. while true do
  54.  local e,p = os.pullEvent()
  55.  if e == "key" then
  56.   local key = p
  57.   if key == 17 or key == 200 then
  58.  
  59.    if nOption > 1 then
  60.     nOption = nOption - 1
  61.     drawMenu()
  62.     drawFrontend()
  63.    end
  64.   elseif key == 31 or key == 208 then
  65.   if nOption < 4 then
  66.   nOption = nOption + 1
  67.   drawMenu()
  68.   drawFrontend()
  69. end
  70. elseif key == 28 then
  71. break
  72. end
  73. end
  74. end
  75. term.clear()
  76.  
  77. --Conditions
  78. if nOption  == 1 then
  79. shell.run("os/.command")
  80. elseif nOption == 2 then
  81. shell.run("os/.programs")
  82. elseif nOption == 3 then
  83. shell.run("os/.shutdown")
  84. else
  85. shell.run("os/.UninstallDialog")
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement