Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local termWidth, termHeight = term.getSize()
- local selectedItem = 1
- local onMainMenu = true
- function Choice1()
- term.clear()
- term.setCursorPos(1,1)
- shell.run("PrintYourOwn")
- end
- function Choice2()
- term.clear()
- shell.run("edittitle")
- end
- function Choice3()
- shell.run("editline")
- end
- function Exit()
- onMainMenu = false
- end
- mainMenu = {
- [1] = { text = "Print A Page", handler = Choice1 },
- [2] = { text = "Edit Title", handler = Choice2},
- [3] = { text = "Edit Line", handeler = Choice3},
- [4] = { text = "Exit", handler = Exit }
- }
- function printMenu( menu )
- for i=1,#menu do
- if i == selectedItem then
- print("-> "..menu[i].text.." <-")
- else
- print(" "..menu[i].text)
- end
- end
- end
- function onKeyPressed( key, menu )
- if key == keys.enter then
- onItemSelected(menu)
- elseif key == keys.up then
- if selectedItem > 1 then
- selectedItem = selectedItem - 1
- end
- elseif key == keys.down then
- if selectedItem < #menu then
- selectedItem = selectedItem + 1
- end
- end
- end
- function onItemSelected( menu )
- menu[selectedItem].handler()
- end
- function main()
- while onMainMenu do
- term.clear()
- term.setCursorPos(1,1)
- printMenu(mainMenu)
- event, key = os.pullEvent("key")
- onKeyPressed(key,mainMenu)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment