Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local headerColor = colors.red
- local monitor
- local width, height
- function getMonitor ()
- for i, v in ipairs(rs.getSides()) do
- if peripheral.getType(v) == "monitor" then
- print("Monitor found on ", v, " side")
- monitor = peripheral.wrap(v)
- width, height = monitor.getSize()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- return
- end
- end
- error("No monitor found")
- end
- function newLine ()
- local x, y = monitor.getCursorPos()
- monitor.setCursorPos(1, y + 1)
- end
- function wordWrap (text)
- local remainingSpace = width
- for word in text:gmatch("%S+") do
- if #word > remainingSpace then
- newLine()
- monitor.write(word .. " ")
- remainingSpace = width - #word - 1
- else
- monitor.write(word .. " ")
- remainingSpace = remainingSpace - #word - 1
- end
- end
- end
- function fillBackground ()
- monitor.setBackgroundColor(colors.blue)
- for y = 1, height do
- for x = 1, width do
- monitor.write(" ")
- end
- newLine()
- end
- monitor.setCursorPos(1, 1)
- end
- function cprint (text)
- for i = 1, width do
- monitor.write(" ")
- end
- newLine()
- for i = 1, (width - #text) / 2 do
- monitor.write(" ")
- end
- monitor.setTextColor(headerColor)
- monitor.write(text)
- for i = 1, (width - #text) / 2 + 1 do
- monitor.write(" ")
- end
- newLine()
- for i = 1, width do
- monitor.write(" ")
- end
- newLine()
- for i = 1, width do
- monitor.write("-")
- end
- monitor.setTextColor(colors.orange)
- end
- function getData ()
- local info = fs.open("/info.txt", "r")
- local infoData = {}
- repeat
- line = info.readLine()
- if line then
- table.insert(infoData, line)
- end
- until line == nil
- info.close()
- return infoData
- end
- function displayInfo ()
- local info = getData()
- fillBackground()
- for i, v in ipairs(info) do
- if i == 1 then
- cprint(v:upper())
- else
- wordWrap(v)
- end
- newLine()
- end
- end
- --Main program
- getMonitor()
- displayInfo()
Advertisement
Add Comment
Please, Sign In to add comment