Advertisement
Guest User

.menu

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