Advertisement
TheSpicePhantom

UnityOS

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