SHOW:
|
|
- or go back to the newest paste.
| 1 | -----------Global Variables--------------- | |
| 2 | slc = 0 | |
| 3 | x, y = term.getSize() | |
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | - | intro() |
| 8 | + | |
| 9 | -------------Programs------------------ | |
| 10 | - | test() |
| 10 | + | |
| 11 | programs = {
| |
| 12 | - | debug() |
| 12 | + | |
| 13 | -- .main | |
| 14 | main = function() | |
| 15 | header() | |
| 16 | - | function header() |
| 16 | + | print(format("Please select a program: "))
|
| 17 | printMenu(Main) | |
| 18 | - | print("=======================================")
|
| 18 | + | input(Main) |
| 19 | - | term.write("| ")
|
| 19 | + | end, |
| 20 | - | term.setTextColor(colors.lightBlue) |
| 20 | + | |
| 21 | - | term.write(" SortBob 1.0 ")
|
| 21 | + | -- .test |
| 22 | - | term.setTextColor(colors.yellow) |
| 22 | + | test = function(inn) |
| 23 | - | term.write(" ["..time().."]")
|
| 23 | + | slc = 1 |
| 24 | - | term.setTextColor(colors.white) |
| 24 | + | clear() |
| 25 | - | term.write(" | ")
|
| 25 | + | term.setCursorPos(1,1) |
| 26 | - | print("=======================================")
|
| 26 | + | print("test")
|
| 27 | - | print(" ")
|
| 27 | + | print(inn) |
| 28 | sleep(1) | |
| 29 | end, | |
| 30 | ||
| 31 | -- .debug | |
| 32 | - | function intro() |
| 32 | + | debug = function() |
| 33 | - | header() |
| 33 | + | slc = 2 |
| 34 | - | print(format("Please select a program: "))
|
| 34 | + | |
| 35 | - | print(format("setLayout"))
|
| 35 | + | print("Dimensions: width = "..x..", height = "..y)
|
| 36 | - | print(format("checkChest"))
|
| 36 | + | input(Debug) |
| 37 | - | print(format("debug"))
|
| 37 | + | end, |
| 38 | - | input() |
| 38 | + | |
| 39 | -- .setLayout | |
| 40 | setLayout = function() | |
| 41 | - | function test() |
| 41 | + | programs["test"]("setLayout")
|
| 42 | shell.run("setLayout")
| |
| 43 | - | print("test")
|
| 43 | + | sleep(1) |
| 44 | - | input() |
| 44 | + | end, |
| 45 | ||
| 46 | checkChest = function() | |
| 47 | - | function debug() |
| 47 | + | test("checkChest")
|
| 48 | - | header() |
| 48 | + | end, |
| 49 | - | print("Dimensions: width = "..x..", height = "..y)
|
| 49 | + | |
| 50 | - | input() |
| 50 | + | -- .home |
| 51 | home = function() | |
| 52 | slc = 0 | |
| 53 | end, | |
| 54 | ||
| 55 | - | function input() |
| 55 | + | -- .goodBye |
| 56 | goodBye = function() | |
| 57 | term.clear() | |
| 58 | - | selection(read()) |
| 58 | + | term.setCursorPos(15,7) |
| 59 | print("Good Bye!")
| |
| 60 | sleep(1) | |
| 61 | - | function selection(input) |
| 61 | + | error() |
| 62 | - | if input == "" then |
| 62 | + | end, |
| 63 | - | clear() |
| 63 | + | } |
| 64 | - | print("Display closed")
|
| 64 | + | |
| 65 | - | error() |
| 65 | + | |
| 66 | ||
| 67 | - | if input == "home" then |
| 67 | + | -- .display |
| 68 | function display() | |
| 69 | clear() | |
| 70 | if slc == 0 then | |
| 71 | - | if input == "set Layout" then |
| 71 | + | programs["main"]() |
| 72 | - | slc = 1 |
| 72 | + | |
| 73 | - | elseif input == "debug" then |
| 73 | + | programs["test"]() |
| 74 | - | slc = 2 |
| 74 | + | |
| 75 | programs["debug"]() | |
| 76 | end | |
| 77 | end | |
| 78 | ||
| 79 | -- .header | |
| 80 | header = function() | |
| 81 | clear() | |
| 82 | print("=======================================")
| |
| 83 | term.write("| ")
| |
| 84 | term.setTextColor(colors.lightBlue) | |
| 85 | term.write(" Display 1.1 ")
| |
| 86 | term.setTextColor(colors.yellow) | |
| 87 | term.write(" ["..time().."]")
| |
| 88 | term.setTextColor(colors.white) | |
| 89 | term.write(" | ")
| |
| 90 | print("=======================================")
| |
| 91 | print(" ")
| |
| 92 | end | |
| 93 | ||
| 94 | -- .input | |
| 95 | function input(menu) | |
| 96 | print("")
| |
| 97 | term.write("Input: ")
| |
| 98 | selection(read(), menu) | |
| 99 | end | |
| 100 | ||
| 101 | -- .selection | |
| 102 | function selection(input, menu) | |
| 103 | if menu == nil then | |
| 104 | menu = General | |
| 105 | end | |
| 106 | for _,v in pairs(menu.getItems()) do | |
| 107 | str = v.getName():gsub("%s+", "")
| |
| 108 | if input == str then | |
| 109 | programs[v.go()]() | |
| 110 | return | |
| 111 | end | |
| 112 | end | |
| 113 | if menu ~= General then | |
| 114 | selection(input, General) | |
| 115 | end | |
| 116 | end | |
| 117 | ||
| 118 | -- .printMenu | |
| 119 | function printMenu(menu) | |
| 120 | for _,v in pairs(menu.getItems()) do | |
| 121 | print(v.getName()) | |
| 122 | end | |
| 123 | end | |
| 124 | ||
| 125 | -- .clear | |
| 126 | function clear() | |
| 127 | term.setCursorPos(1,1) | |
| 128 | term.clear() | |
| 129 | end | |
| 130 | ||
| 131 | -- .format | |
| 132 | function format(str) | |
| 133 | length = string.len(str) | |
| 134 | spaces = math.floor((x - length)/2) | |
| 135 | for i = 1,spaces do | |
| 136 | str = " "..str.." " | |
| 137 | end | |
| 138 | if string.len(str) < x then | |
| 139 | str = str.." " | |
| 140 | end | |
| 141 | return str | |
| 142 | end | |
| 143 | ||
| 144 | -- .time | |
| 145 | function time() | |
| 146 | local time = os.time() | |
| 147 | h = math.floor(time) | |
| 148 | m = math.floor((time-h)*100) | |
| 149 | if h < 10 then | |
| 150 | h = "0"..h | |
| 151 | end | |
| 152 | if m < 10 then | |
| 153 | m = "0"..m | |
| 154 | end | |
| 155 | return (h..":"..m) | |
| 156 | end | |
| 157 | ||
| 158 | -----------Initialization--------------- | |
| 159 | shell.run("Menu")
| |
| 160 | Main = Menu("Main")
| |
| 161 | Main.addItem(format("setLayout"), "setLayout")
| |
| 162 | Main.addItem(format("checkChest"), "checkChest")
| |
| 163 | Main.addItem(format("debug"), "debug")
| |
| 164 | ||
| 165 | Debug = Menu("Debug")
| |
| 166 | Debug.addItem("test", "test")
| |
| 167 | ||
| 168 | General = Menu("General")
| |
| 169 | General.addItem("home", "home")
| |
| 170 | General.addItem("h", "home")
| |
| 171 | General.addItem("debug", "debug")
| |
| 172 | General.addItem("test", "test")
| |
| 173 | General.addItem("", "goodBye")
| |
| 174 | ||
| 175 | ||
| 176 | -------------Main-------------- | |
| 177 | while true do | |
| 178 | display() | |
| 179 | end |