Gokborg

GokOS

Oct 10th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. --Menu System
  2. local WIDTH, HEIGHT = term.getSize()
  3. local menuItems = {
  4.    
  5.     {
  6.         "OS Update",
  7.         function()
  8.             term.clear()
  9.             term.setCursorPos(1,1)
  10.             term.write("Updating...")
  11.             os.sleep(1)
  12.             if fs.exists("startup") then
  13.                 shell.run("delete startup")
  14.             end
  15.             shell.run("pastebin get vpMfYK0v startup")
  16.             os.reboot()
  17.         end
  18.     },
  19.  
  20.     {
  21.         "Programs",
  22.         function()
  23.             term.clear()
  24.             term.setCursorPos(1,1)
  25.             term.write("No functionality yet!")
  26.             os.sleep(1)
  27.             return
  28.         end
  29.     },
  30.    
  31.     {
  32.         "Install",
  33.         function()
  34.             term.clear()
  35.             term.setCursorPos(1,1)
  36.             term.write("Soon to be way of installing ur fav programs")
  37.             os.sleep(1)
  38.         end
  39.     },
  40.  
  41.     {
  42.         "Quit",
  43.         function()
  44.             term.clear()
  45.             term.setCursorPos(1,1)
  46.             term.write("Shutting down...")
  47.             os.sleep(1)
  48.             return true
  49.         end
  50.     }
  51.    
  52. }
  53.  
  54. function runSelection(option)
  55.     return menuItems[option][2]()
  56. end
  57.  
  58. function initScreen()
  59.     term.clear()
  60.     term.setCursorPos(1,1)
  61.    
  62.     --Check if installation is proper etc..
  63. end
  64.  
  65. --Prints text in the center of a selected row
  66. function printCenter(h, msg)
  67.     term.setCursorPos(math.floor((WIDTH-string.len(msg))/2), h)
  68.     term.clearLine()
  69.     term.write(msg)
  70. end
  71.  
  72. function drawMenu(option)
  73.     term.clear()
  74.     for i, item in ipairs(menuItems) do
  75.         if i == option then
  76.             term.setTextColor(colors.lightBlue)
  77.             printCenter(i+3, "["..item[1].."]")
  78.             term.setTextColor(colors.white)
  79.         else
  80.             printCenter(i+3, item[1])
  81.         end
  82.     end
  83. end
  84.  
  85. --TODO: Add a function for checking on updates (FOR NOW JUST GETS STARTUP)
  86.  
  87.  
  88. initScreen()
  89. local option = 1
  90.  
  91. while true do
  92.    
  93.     drawMenu(option)
  94.    
  95.     local event, key = os.pullEvent("key")
  96.    
  97.     if key == keys.up then
  98.         option = option - 1
  99.     elseif key == keys.down then
  100.         option = option + 1
  101.     end
  102.    
  103.     --Bound check options
  104.     if option > table.getn(menuItems) then
  105.         option = option - 1
  106.     elseif option == 0 then
  107.         option = option + 1
  108.     end
  109.    
  110.     drawMenu(option)
  111.    
  112.     if key == keys.enter then
  113.         if runSelection(option) == true then
  114.             term.clear()
  115.             term.setCursorPos(1,1)
  116.             break
  117.         end
  118.     end
  119. end
Add Comment
Please, Sign In to add comment