Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- init globals
- os.loadAPI("endos/apis/etu")
- TermWidth, TermHeight = term.getSize()
- SelectedItem = 1
- Running = true
- -- input handler
- local function on_key_pressed(key, menu)
- if key == keys.enter then
- menu[SelectedItem].handler()
- elseif key == keys.up and SelectedItem > 1 then
- SelectedItem = SelectedItem - 1
- elseif key == keys.down and SelectedItem < #menu then
- SelectedItem = SelectedItem + 1
- end
- end
- --printing methods
- local function print_menu(menu)
- for i = 1, #menu do
- if i == SelectedItem then
- etu.print_centered(3+i, ">> " .. menu[i].text .. " <<")
- else
- etu.print_centered(3+i, " " .. menu[i].text .. " ")
- end
- end
- end
- --menu methods
- function Host_Server()
- print("wip")
- sleep(2)
- end
- function Settings()
- print("wip")
- sleep(2)
- end
- function Command_Line()
- Running = false
- shell.run("endos/.cmd")
- end
- function Restart()
- os.reboot()
- end
- function Shut_Down()
- os.shutdown()
- end
- --menu def
- MainMenu = {
- [1] = {text = "Host Server", handler = Host_Server},
- [2] = {text = "Settings", handler = Settings},
- [3] = {text = "Command line", handler = Command_Line},
- [4] = {text = "Restart", handler = Restart},
- [5] = {text = "Shutdown", handler = Shut_Down}
- }
- function Main()
- while Running do
- term.clear()
- term.setCursorPos(1,1)
- print_menu(MainMenu)
- local event, key = os.pullEvent("key")
- on_key_pressed(key, MainMenu)
- end
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement