Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PostMonitor module - Basic debugging / logging put on a monitor
- local displayModem = dbModem
- function checkMonitor(monitorName)
- if not displayModem.isPresentRemote(monitorName) then
- print("Missing post monitor")
- print("Change 'displayMonitorName' to any of the following values if applicable")
- for _, name in displayModem.getNamesRemote() do
- print(" >'"..name.."'")
- end
- return
- end
- end
- function wrapPostMonitor(monitorName)
- local display = peripheral.wrap(monitorName)
- display.setBackgroundColour(0x8000)
- display.clear()
- display.setCursorPos(1,1)
- display.setCursorBlink(true)
- display.setTextScale(0.5)
- nextLine = function (monitor, screenHeight)
- local newYPos = ({monitor.getCursorPos()})[2]
- if (newYPos >= screenHeight) then
- monitor.scroll(1)
- else
- newYPos = newYPos + 1
- end
- monitor.setCursorPos(1, newYPos)
- end
- writeWrapped = function(postMonitor, log)
- local maxLineLength, screenHeight = postMonitor.display.getSize()
- local lineLength = 0
- local words = {}
- for word in log:gmatch("%S*%s?") do table.insert(words, word) end
- for index, word in pairs(words) do
- lineLength = lineLength + word:len() +1
- if (lineLength > maxLineLength) then
- nextLine(postMonitor.display, screenHeight)
- lineLength = 0
- end
- postMonitor.display.write(word .. (index ~= #words and " " or ""))
- end
- nextLine(postMonitor.display, screenHeight)
- end
- return {
- display = display,
- postLog = function(postMonitor, log)
- postMonitor:resetColor()
- writeWrapped(postMonitor, log)
- end,
- postError = function(postMonitor, log)
- postMonitor:textColor(0x4000)
- writeWrapped(postMonitor, log)
- end,
- resetColor = function(postMonitor)
- postMonitor.display.setBackgroundColour(0x8000)
- postMonitor.display.setTextColour(0x1)
- end,
- textColor = function(postMonitor, color)
- postMonitor:resetColor()
- postMonitor.display.setTextColour(color)
- end,
- paintColor = function(postMonitor, color)
- postMonitor.display.setBackgroundColour(color)
- postMonitor.display.setTextColour(color)
- end,
- }
- end
- function safeWrapPostMonitor(monitorName)
- checkMonitor(monitorName)
- return wrapPostMonitor(monitorName)
- end
- --End of PostMonitor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement