Wiiplay123

Teh's Custom Billboard

Feb 17th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.72 KB | None | 0 0
  1. -- Settings
  2. function prog()
  3. local delay = 5
  4. local strings2 = {}
  5. local strings = {}
  6. for i, v in pairs(fs.list("ftp")) do
  7.     local f = fs.open(fs.combine("ftp",v),"r")
  8.     table.insert(strings2,f.readAll())
  9.     f.close()
  10. end
  11. if strings ~= strings2 then
  12.     strings = strings2
  13. end
  14. assert(#strings[1], "Please input a string!")
  15. local mon = nil
  16. for _, side in pairs(rs.getSides()) do
  17.  if peripheral.getType(side) == "monitor" then
  18.     mon = peripheral.wrap(side)
  19.  end
  20. end
  21. assert(mon, "No monitor found")
  22. mon.setTextScale(5)
  23. local w, h = mon.getSize()
  24.  
  25. local function strLen(str)
  26.  str = str:gsub("&[0-9a-fA-F]", ""):gsub("&&", "&")
  27.  return #str
  28. end
  29.  
  30. local function centerWrite(str)
  31.  mon.clear()
  32.  mon.setTextColor(colors.white)
  33.  local lines = {}
  34.  local words = {}
  35.  local l = 0
  36.  for word in str:gmatch("[^ ]+") do
  37.     if l == 0 or #lines[l] + strLen(word) > w then
  38.      l = l + 1
  39.      lines[l] = word
  40.     else
  41.      lines[l] = lines[l] .. " " .. word
  42.     end
  43.  end
  44.  
  45.  local y = math.floor((h - #lines) / 2)
  46.  if y < 0 then y = 0 end
  47.  for l = 1, #lines do
  48.     local line = lines[l]
  49.     local x = math.floor((w - strLen(line)) / 2) + 1
  50.     mon.setCursorPos(x, l + y)
  51.     local escape = false
  52.     for c = 1, #line do
  53.      local char = line:sub(c, c)
  54.      if escape then
  55.         char = char:lower()
  56.         if char == "0" then mon.setTextColor(colors.black)
  57.         elseif char == "1" then mon.setTextColor(colors.blue)
  58.         elseif char == "2" then mon.setTextColor(colors.green)
  59.         elseif char == "3" then mon.setTextColor(colors.brown)
  60.         elseif char == "4" then mon.setTextColor(colors.red)
  61.         elseif char == "5" then mon.setTextColor(colors.purple)
  62.         elseif char == "6" then mon.setTextColor(colors.orange)
  63.         elseif char == "7" then mon.setTextColor(colors.lightGray)
  64.         elseif char == "8" then mon.setTextColor(colors.gray)
  65.         elseif char == "9" then mon.setTextColor(colors.lightBlue)
  66.         elseif char == "a" then mon.setTextColor(colors.lime)
  67.         elseif char == "b" then mon.setTextColor(colors.cyan)
  68.         elseif char == "c" then mon.setTextColor(colors.pink)
  69.         elseif char == "d" then mon.setTextColor(colors.magenta)
  70.         elseif char == "e" then mon.setTextColor(colors.yellow)
  71.         elseif char == "f" then mon.setTextColor(colors.white)
  72.         elseif char == "&" then mon.write("&")
  73.         end
  74.         escape = false
  75.      elseif char == "&" then
  76.         escape = true
  77.      else
  78.         mon.write(char)
  79.      end
  80.     end
  81.  end
  82. end
  83.  
  84. local i = 1
  85. while true do
  86.  centerWrite(strings[i])
  87.  i = i % #strings + 1
  88. strings = {}
  89.  for i, v in pairs(fs.list("ftp")) do
  90.     local f = fs.open(fs.combine("ftp",v),"r")
  91.     table.insert(strings2,f.readAll())
  92.     f.close()
  93.  end
  94.  if strings ~= strings2 then
  95.     strings = strings2
  96.     if i > #strings then
  97.         i = 1
  98.     end
  99.  end
  100.  sleep(delay)
  101. end
  102. end
  103. parallel.waitForAny((function() shell.run("ftpserv") end),prog)
Advertisement
Add Comment
Please, Sign In to add comment