Advertisement
RabaGhast

Display_1.1

Nov 7th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -----------Global Variables---------------
  2. slc = 0
  3. x, y = term.getSize()
  4.  
  5.  
  6.  
  7.  
  8.  
  9. -------------Programs------------------
  10.  
  11. programs = {
  12.  
  13.   --                                                                    .main
  14.   main = function()
  15.     header()
  16.     print(format("Please select a program: "))
  17.     printMenu(Main)
  18.     input(Main)
  19.   end,
  20.  
  21.   --                                                                    .test
  22.   test = function(inn)
  23.     slc = 1
  24.     clear()
  25.     term.setCursorPos(1,1)
  26.     print("test")
  27.     print(inn)
  28.     sleep(1)
  29.   end,
  30.  
  31.   --                                                                    .debug
  32.   debug = function()
  33.     slc = 2
  34.     header()
  35.     print("Dimensions: width = "..x..", height = "..y)
  36.     input(Debug)
  37.   end,
  38.  
  39.   --                                                                    .setLayout
  40.   setLayout = function()
  41.     programs["test"]("setLayout")
  42.     shell.run("setLayout")
  43.     sleep(1)
  44.   end,
  45.  
  46.   checkChest = function()
  47.     test("checkChest")
  48.   end,
  49.  
  50.   --                                                                    .home
  51.   home = function()
  52.     slc = 0
  53.   end,
  54.  
  55.   --                                                                    .goodBye
  56.   goodBye = function()
  57.     term.clear()
  58.     term.setCursorPos(15,7)
  59.     print("Good Bye!")
  60.     sleep(1)
  61.     error()
  62.   end,
  63. }
  64.  
  65. -----------Functions---------------
  66.  
  67. --                                                                    .display
  68. function display()
  69.   clear()
  70.   if slc == 0 then
  71.     programs["main"]()
  72.   elseif slc == 1 then
  73.     programs["test"]()
  74.   elseif slc == 2 then
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement