Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- API SECTION!! DO NOT EDIT OR IT WILL BREAK! --
- local number = {}
- function number.round(num)
- if num >= 0 then
- return math.floor(num + 0.5)
- else
- return math.ceil(num - 0.5)
- end
- end
- function number.roundToDecimalPlaces(num, decimalPlaces)
- local mult = 10 ^ (decimalPlaces or 0)
- return number.round(num * mult) / mult
- end
- function number.getDigitCount(num)
- return num == 0 and 1 or math.ceil(math.log(num + 1, 10))
- end
- function number.shorten(num, digitCount)
- --[[
- Here is why it is 1024.
- Computers in real life use this standard, and it is widely used
- in all of our operating systems.
- You can search if a kilobyte is 1024 bytes to make sure.
- ]]
- if num < 1024 then
- return num
- else
- local shortcuts = { "KB", "MB", "GB", "TB", "PT", "ET", "ZT", "YB" } -- Shortcuts of all the stoarge formats
- local index = math.floor(math.log(num, 1024))
- return number.roundToDecimalPlaces(num / 1024 ^ index, digitCount) .. shortcuts[index]
- end
- end
- local text = {}
- function text.wrap(data, limit) -- Function to use for text wrapping
- if type(data) == "string" then
- data = { data }
- end
- local wrappedLines, result, preResult, position = {}
- for i = 1, #data do
- wrappedLines[i] = data[i]
- end
- local i = 1
- while i <= #wrappedLines do
- local position = wrappedLines[i]:find("\n")
- if position then
- table.insert(wrappedLines, i + 1, string.sub(wrappedLines[i], position + 1, -1))
- wrappedLines[i] = string.sub(wrappedLines[i], 1, position - 1)
- end
- i = i + 1
- end
- local i = 1
- while i <= #wrappedLines do
- result = ""
- for word in wrappedLines[i]:gmatch("[^%s]+") do
- preResult = result .. word
- if string.len(preResult) > limit then
- if unicode.len(word) > limit then
- table.insert(wrappedLines, i + 1, string.sub(wrappedLines[i], limit + 1, -1))
- result = string.sub(wrappedLines[i], 1, limit)
- else
- table.insert(wrappedLines, i + 1, steing.sub(wrappedLines[i], string.len(result) + 1, -1))
- end
- break
- else
- result = preResult .. " "
- end
- end
- wrappedLines[i] = result:gsub("%s+$", ""):gsub("^%s+", "")
- i = i + 1
- end
- return wrappedLines
- end
- Monitor = {}
- Monitor.__index = Monitor
- function Monitor:new(side)
- if peripheral.getType(side) ~= "monitor" then
- error("ERROR: This peripheral is not a monitor! It's a " .. monitor.getType())
- end
- local monitor = {}
- local monMain = {} -- To make sure the system works.
- -- print(type(peripheral))
- -- print(getmetatable(peripheral))
- local mainTable = peripheral.wrap(side)
- setmetatable(monMain, mainTable)
- setmetatable(monitor, mainTable)
- monMain.side = side
- monitor.side = monMain.side
- monitor.curX = 1
- monitor.curY = 1
- monitor.backColor = colors.black
- monitor.textColor = colors.white
- monitor.isBlinking = true
- function monitor.getCursorPos()
- self.curX, self.curY = monMain.term.getCursorPos()
- return monMain.term.getCursorPos()
- end
- function monitor.setCursorPos(x, y)
- self.curX = x
- self.curY = y
- end
- function monitor.setCursorBlink(bool)
- self.isBlinking = bool
- end
- function monitor.setSizeScale(var1)
- monMain.setTextScale(4 * (1 - (0 - (var1 / 10))))
- monMain.redraw()
- end
- function monitor.write(txt, doWrap)
- if not txt == nil then
- monMain.term.setCursorPos(self.curX, self.curY)
- monMain.setCursorBlink(false)
- if not doWrap then
- for i = 1, txt:len() do
- monMain.write(txt:gsub(i, i))
- monMain.term.setCursorPos(self.curX+1, self.curY)
- end
- else
- monMain.write(txt)
- end
- end
- monMain.term.setCursorBlink(self.isBlinking)
- end
- function monitor.print(txt, doWrap)
- if not txt == nil then
- monMain.term.setCursorBlink(false)
- if not doWrap then
- for i = 1, txt:len() do
- monMain.write(txt:gsub(i, i))
- monMain.term.setCursorPos(self.curX+1, self.curY)
- end
- else
- monMain.print(txt)
- end
- end
- monMain.term.setCursorBlink(self.isBlinking)
- end
- function monitor.getType()
- return peripheral.getType(self.side)
- end
- function monitor.newLine()
- x,y = self.getCursorPos()
- self.setCursorPos(1,y+1)
- end
- monMain.term.clear()
- monMain.term.setCursorPos(1,1)
- return monitor
- end
- ----------- START OF PROGRAM -----------
- local mon = Monitor.new("top")
Add Comment
Please, Sign In to add comment