SHOW:
|
|
- or go back to the newest paste.
| 1 | local termWidth, termHeight = term.getSize() | |
| 2 | local selectedItem = 1 | |
| 3 | local onMainMenu = true | |
| 4 | ||
| 5 | function Choice1() | |
| 6 | term.clear() | |
| 7 | term.setCursorPos(1,1) | |
| 8 | - | print("CHOICE 1")
|
| 8 | + | shell.run("PrintYourOwn")
|
| 9 | - | sleep(1) |
| 9 | + | |
| 10 | ||
| 11 | function Choice2() | |
| 12 | term.clear() | |
| 13 | shell.run("edittitle")
| |
| 14 | end | |
| 15 | ||
| 16 | function Choice3() | |
| 17 | - | [1] = { text = "Choice 1", handler = Choice1 },
|
| 17 | + | shell.run("editline")
|
| 18 | - | [2] = { text = "Exit", handler = Exit }
|
| 18 | + | |
| 19 | ||
| 20 | function Exit() | |
| 21 | onMainMenu = false | |
| 22 | end | |
| 23 | ||
| 24 | - | print(">> "..menu[i].text)
|
| 24 | + | |
| 25 | [1] = { text = "Print A Page", handler = Choice1 },
| |
| 26 | [2] = { text = "Edit Title", handler = Choice2},
| |
| 27 | [3] = { text = "Edit Line", handeler = Choice3},
| |
| 28 | [4] = { text = "Exit", handler = Exit }
| |
| 29 | } | |
| 30 | ||
| 31 | function printMenu( menu ) | |
| 32 | for i=1,#menu do | |
| 33 | if i == selectedItem then | |
| 34 | print("-> "..menu[i].text.." <-")
| |
| 35 | else | |
| 36 | print(" "..menu[i].text)
| |
| 37 | end | |
| 38 | end | |
| 39 | end | |
| 40 | ||
| 41 | function onKeyPressed( key, menu ) | |
| 42 | if key == keys.enter then | |
| 43 | onItemSelected(menu) | |
| 44 | elseif key == keys.up then | |
| 45 | if selectedItem > 1 then | |
| 46 | selectedItem = selectedItem - 1 | |
| 47 | end | |
| 48 | elseif key == keys.down then | |
| 49 | if selectedItem < #menu then | |
| 50 | selectedItem = selectedItem + 1 | |
| 51 | end | |
| 52 | end | |
| 53 | end | |
| 54 | ||
| 55 | function onItemSelected( menu ) | |
| 56 | menu[selectedItem].handler() | |
| 57 | end | |
| 58 | ||
| 59 | function main() | |
| 60 | while onMainMenu do | |
| 61 | term.clear() | |
| 62 | term.setCursorPos(1,1) | |
| 63 | printMenu(mainMenu) | |
| 64 | event, key = os.pullEvent("key")
| |
| 65 | onKeyPressed(key,mainMenu) | |
| 66 | end | |
| 67 | end | |
| 68 | ||
| 69 | main() |