Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------Global Variables---------------
- slc = 0
- x, y = term.getSize()
- -------------Programs------------------
- programs = {
- -- .main
- main = function()
- header()
- print(format("Please select a program: "))
- printMenu(Main)
- input(Main)
- end,
- -- .test
- test = function(inn)
- slc = 1
- clear()
- term.setCursorPos(1,1)
- print("test")
- print(inn)
- sleep(1)
- end,
- -- .debug
- debug = function()
- slc = 2
- header()
- print("Dimensions: width = "..x..", height = "..y)
- input(Debug)
- end,
- -- .setLayout
- setLayout = function()
- programs["test"]("setLayout")
- shell.run("setLayout")
- sleep(1)
- end,
- checkChest = function()
- test("checkChest")
- end,
- -- .home
- home = function()
- slc = 0
- end,
- -- .goodBye
- goodBye = function()
- term.clear()
- term.setCursorPos(15,7)
- print("Good Bye!")
- sleep(1)
- error()
- end,
- }
- -----------Functions---------------
- -- .display
- function display()
- clear()
- if slc == 0 then
- programs["main"]()
- elseif slc == 1 then
- programs["test"]()
- elseif slc == 2 then
- programs["debug"]()
- end
- end
- -- .header
- header = function()
- clear()
- print("=======================================")
- term.write("| ")
- term.setTextColor(colors.lightBlue)
- term.write(" Display 1.1 ")
- term.setTextColor(colors.yellow)
- term.write(" ["..time().."]")
- term.setTextColor(colors.white)
- term.write(" | ")
- print("=======================================")
- print(" ")
- end
- -- .input
- function input(menu)
- print("")
- term.write("Input: ")
- selection(read(), menu)
- end
- -- .selection
- function selection(input, menu)
- if menu == nil then
- menu = General
- end
- for _,v in pairs(menu.getItems()) do
- str = v.getName():gsub("%s+", "")
- if input == str then
- programs[v.go()]()
- return
- end
- end
- if menu ~= General then
- selection(input, General)
- end
- end
- -- .printMenu
- function printMenu(menu)
- for _,v in pairs(menu.getItems()) do
- print(v.getName())
- end
- end
- -- .clear
- function clear()
- term.setCursorPos(1,1)
- term.clear()
- end
- -- .format
- function format(str)
- length = string.len(str)
- spaces = math.floor((x - length)/2)
- for i = 1,spaces do
- str = " "..str.." "
- end
- if string.len(str) < x then
- str = str.." "
- end
- return str
- end
- -- .time
- function time()
- local time = os.time()
- h = math.floor(time)
- m = math.floor((time-h)*100)
- if h < 10 then
- h = "0"..h
- end
- if m < 10 then
- m = "0"..m
- end
- return (h..":"..m)
- end
- -----------Initialization---------------
- shell.run("Menu")
- Main = Menu("Main")
- Main.addItem(format("setLayout"), "setLayout")
- Main.addItem(format("checkChest"), "checkChest")
- Main.addItem(format("debug"), "debug")
- Debug = Menu("Debug")
- Debug.addItem("test", "test")
- General = Menu("General")
- General.addItem("home", "home")
- General.addItem("h", "home")
- General.addItem("debug", "debug")
- General.addItem("test", "test")
- General.addItem("", "goodBye")
- -------------Main--------------
- while true do
- display()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement