Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitors = ""
- function setMonitors(monitortable)
- if(type(monitortable) == "table")then
- monitors = monitortable
- return true
- end
- return false
- end
- function checkMonitors()
- if(type(monitors) == "table")then
- return true
- end
- term.setTextColor(colors.red)
- print("Error: No monitors defined!")
- error()
- end
- function printNames()
- checkMonitors()
- list = peripheral.getNames();
- for i, d in pairs(list) do
- if(peripheral.getType(d) == "monitor")then
- mon = peripheral.wrap(d)
- mon.clear()
- mon.setCursorPos(1, 1)
- mon.write(d)
- end
- end
- end
- function getSize()
- checkMonitors()
- ySize = 0
- for _, _S in pairs(monitors) do
- xSize = 0
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- w, h = mon.getSize()
- xSize = xSize + w
- end
- ySize = ySize + h
- end
- return xSize, ySize
- end
- function setCursorPos(x, y)
- checkMonitors()
- yNeg = 0
- for _, _S in pairs(monitors) do
- xNeg = 0
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- w, h = mon.getSize()
- mon.setCursorPos(0 - xNeg + x, 0 - yNeg + y)
- xNeg = xNeg + w
- end
- yNeg = yNeg + h
- end
- end
- function getCursorPos()
- checkMonitors()
- mon = peripheral.wrap("monitor_" .. monitors[1][1])
- return mon.getCursorPos()
- end
- function writeText(text)
- checkMonitors()
- w, h = getSize()
- for _, _S in pairs(monitors) do
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- mon.write(text)
- end
- end
- end
- function printText(text)
- checkMonitors()
- width, height = getSize()
- oldx, oldy = getCursorPos()
- wrapped = calcWrap(text, width - oldx)
- for row = 1, #wrapped do
- writeText(wrapped[row])
- setCursorPos(oldx, oldy+row)
- end
- end
- function slowPrintText(text, speed)
- checkMonitors()
- width, height = getSize()
- oldx, oldy = getCursorPos()
- wrapped = calcWrap(text, width - oldx)
- for row = 1, #wrapped do
- for hg = 1, string.len(wrapped[row]) do
- writeText(string.sub(wrapped[row], hg, hg))
- sleep(speed)
- end
- setCursorPos(oldx, oldy+row)
- end
- end
- function setBackgroundColor(color)
- checkMonitors()
- for _, _S in pairs(monitors) do
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- mon.setBackgroundColor(color)
- end
- end
- end
- function setTextColor(color)
- checkMonitors()
- for _, _S in pairs(monitors) do
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- mon.setTextColor(color)
- end
- end
- end
- function fillBox(x, y, width, height, character)
- checkMonitors()
- for xPos = 0, width-1 do
- for yPos = 0, height-1 do
- setCursorPos(xPos+x, yPos+y)
- writeText(character)
- end
- end
- end
- function clear()
- checkMonitors()
- for _, _S in pairs(monitors) do
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- mon.clear()
- end
- end
- end
- function clearLine(y)
- checkMonitors()
- for _, _S in pairs(monitors) do
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- for x = 1, w do
- setCursorPos(x, y)
- writeText(" ")
- end
- end
- end
- end
- function calcWrap(text, width)
- lines = {""}
- for word, space in text:gmatch('(%S+)(%s*)') do
- temp = lines[#lines] .. word .. space:gsub('\n','')
- if #temp > width then
- table.insert(lines, '')
- end
- if space:find('\n') then
- lines[#lines] = lines[#lines] .. word
- space = space:gsub('\n', function()
- table.insert(lines, '')
- return ''
- end)
- else
- lines[#lines] = lines[#lines] .. word .. space
- end
- end
- return lines
- end
- function setTextScale(scale)
- checkMonitors()
- for _, _S in pairs(monitors) do
- for i, d in pairs(_S) do
- mon = peripheral.wrap("monitor_" .. d)
- mon.setTextScale(scale)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement