Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local headerColor = colors.lightBlue
- 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 - 2
- monitor.write(" ")
- for word in text:gmatch("[a-zA-Z0-9!.,-]+") do
- if #word > remainingSpace then
- newLine()
- monitor.write(" " .. word .. " ")
- remainingSpace = width - #word - 2
- else
- monitor.write(word .. " ")
- remainingSpace = remainingSpace - #word - 2
- end
- end
- end
- function drawBackground (color)
- monitor.setBackgroundColor(color)
- monitor.clear()
- end
- function centerPrint (lineNumber, textColor, text)
- monitor.setCursorPos((width - #text) / 2, lineNumber)
- monitor.setTextColor(textColor)
- monitor.write(text)
- 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
- --Draw a filled box for e.g. a button or shadow
- function drawBox (x, y, width, height, color)
- monitor.setBackgroundColor(color)
- monitor.setTextColor(color)
- for i = 0, height - 1 do
- monitor.setCursorPos(x, y + i)
- for j = 1, width do
- monitor.write(" ")
- end
- end
- end
- function drawHeader (fillColor, textColor, text)
- --Draw shadow
- drawBox(4, 3, width - 5, 3, colors.lightGray)
- --Draw header box
- drawBox(3, 2, width - 5, 3, fillColor)
- --Write text
- monitor.setTextColor(textColor)
- centerPrint(3, textColor, text)
- monitor.setCursorPos(1, 6)
- monitor.setBackgroundColor(colors.white)
- end
- function displayInfo ()
- local info = getData()
- drawBackground(colors.white)
- for i, v in ipairs(info) do
- if i == 1 then
- drawHeader(colors.red, colors.orange, v:upper())
- else
- wordWrap(v)
- end
- newLine()
- end
- end
- --Main program
- getMonitor()
- displayInfo()
Advertisement
Add Comment
Please, Sign In to add comment