Advertisement
RabaGhast

Display

Nov 3rd, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. slc = 0
  2. x, y = term.getSize()
  3.  
  4. function display()
  5.   clear()
  6.   if slc == 0 then
  7.     header()
  8.     intro()
  9.   elseif slc == 1 then
  10.     test()
  11.   elseif slc == 2 then
  12.     debug()
  13.   end
  14. end
  15.  
  16. function header()
  17.   clear()
  18.   print("=======================================")
  19.   term.write("|            ")
  20.   term.setTextColor(colors.lightBlue)
  21.   term.write(" SortBob 1.0  ")
  22.   term.setTextColor(colors.yellow)
  23.   term.write("   ["..time().."]")
  24.   term.setTextColor(colors.white)
  25.   term.write(" | ")
  26.   print("=======================================")
  27.   print(" ")
  28. end
  29.  
  30. -------------Programs------------------
  31.  
  32. function intro()
  33.   header()
  34.   print(format("Please select a program: "))
  35.   print(format("setLayout"))
  36.   print(format("checkChest"))
  37.   print(format("debug"))
  38.   input()
  39. end
  40.  
  41. function test()
  42.   clear()
  43.   print("test")
  44.   input()
  45. end
  46.  
  47. function debug()
  48.   header()
  49.   print("Dimensions: width = "..x..", height = "..y)
  50.   input()
  51. end
  52.  
  53. -----------Functions---------------
  54.  
  55. function input()
  56.   print("")
  57.   term.write("Input: ")
  58.   selection(read())
  59. end
  60.  
  61. function selection(input)
  62.   if input == "" then
  63.       clear()
  64.       print("Display closed")
  65.       error()
  66.   end
  67.   if input == "home" then
  68.     slc = 0
  69.   end
  70.   if slc == 0 then
  71.     if  input == "set Layout" then
  72.       slc = 1
  73.     elseif input == "debug" then
  74.       slc = 2
  75.     end
  76.   end
  77. end
  78.  
  79. function clear()
  80.   term.setCursorPos(1,1)
  81.   term.clear()
  82. end
  83.  
  84. function format(str)
  85.   length = string.len(str)
  86.   spaces = math.floor((x - length)/2)
  87.   for i = 1,spaces do
  88.     str = " "..str.." "
  89.   end
  90.   if string.len(str) < x then
  91.     str = str.." "
  92.   end
  93.   return str
  94. end
  95.  
  96. function time()
  97.   local time = os.time()
  98.   h = math.floor(time)
  99.   m = math.floor((time-h)*100)
  100.   if h < 10 then
  101.     h = "0"..h
  102.   end
  103.   if m < 10 then
  104.     m = "0"..m
  105.   end
  106.   return (h..":"..m)
  107. end
  108. -------------Main--------------
  109. while true do
  110.   display()
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement