Advertisement
DYankee

startmenu

Oct 5th, 2022 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. -- init globals
  2. os.loadAPI("endos/apis/etu")
  3. TermWidth, TermHeight = term.getSize()
  4. SelectedItem = 1
  5. Running = true
  6.  
  7. -- input handler
  8. local function on_key_pressed(key, menu)
  9.     if key == keys.enter then
  10.         menu[SelectedItem].handler()
  11.     elseif key == keys.up and SelectedItem > 1 then
  12.         SelectedItem = SelectedItem - 1
  13.     elseif key == keys.down and SelectedItem < #menu then
  14.         SelectedItem = SelectedItem + 1
  15.     end
  16. end
  17.  
  18. --printing methods
  19. local function print_menu(menu)
  20.     for i = 1, #menu do
  21.         if i == SelectedItem then
  22.             etu.print_centered(3+i, ">> " .. menu[i].text .. " <<")
  23.         else
  24.             etu.print_centered(3+i, "   " .. menu[i].text .. "   ")
  25.         end
  26.     end
  27. end
  28.  
  29. --menu methods
  30. function Host_Server()
  31.     print("wip")
  32.     sleep(2)
  33. end
  34.  
  35. function Settings()
  36.     print("wip")
  37.     sleep(2)
  38. end
  39.  
  40. function Command_Line()
  41.     Running = false
  42.     shell.run("endos/.cmd")
  43. end
  44.  
  45. function Restart()
  46.     os.reboot()
  47. end
  48.  
  49. function Shut_Down()
  50.     os.shutdown()
  51. end
  52.  
  53. --menu def
  54. MainMenu = {
  55.     [1] = {text = "Host Server", handler = Host_Server},
  56.     [2] = {text = "Settings", handler = Settings},
  57.     [3] = {text = "Command line", handler = Command_Line},
  58.     [4] = {text = "Restart", handler = Restart},
  59.     [5] = {text = "Shutdown", handler = Shut_Down}
  60. }
  61.  
  62. function Main()
  63.     while Running do
  64.         term.clear()
  65.         term.setCursorPos(1,1)
  66.         print_menu(MainMenu)
  67.  
  68.         local event, key = os.pullEvent("key")
  69.         on_key_pressed(key, MainMenu)
  70.     end
  71. end
  72.  
  73. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement