Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bufferAPI = {}
- bufferAPI.term = _G.term
- -- Colour Manager
- bufferAPI.colour = {}
- bufferAPI.colour.tohex = {[1] = "0",[2] = "1",[4] = "2",[8] = "3",[16] = "4",[32] = "5",[64] = "6",[128] = "7",[256] = "8",[512] = "9",[1024] = "a",[2048] = "b",[4098] = "c",[8192] = "d",[16384] = "e",[32768] = "f"}
- bufferAPI.colour.todec = {}
- for i,k in pairs(bufferAPI.colour.tohex) do
- bufferAPI.colour.todec[k] = i
- end
- -- Buffer Manager
- bufferAPI.buffer = {}
- bufferAPI.buffer.textColour = bufferAPI.colour.tohex[term.getTextColour()]
- bufferAPI.buffer.backColour = bufferAPI.colour.tohex[term.getBackgroundColour()]
- bufferAPI.buffer.cursorX = 1
- bufferAPI.buffer.cursorY = 1
- bufferAPI.buffer.width , bufferAPI.buffer.height = term.getSize()
- -- Default Term
- function bufferAPI.getCursorPos()
- return bufferAPI.buffer.cursorX , bufferAPI.buffer.cursorY
- end
- function bufferAPI.current()
- return bufferAPI
- end
- function bufferAPI.getBackgroundColour()
- return bufferAPI.buffer.backColour
- end
- function bufferAPI.getTextColour()
- return bufferAPI.buffer.textColour
- end
- function bufferAPI.scroll(nA)
- --WIP
- end
- function bufferAPI.redirect(tT)
- return bufferAPI.term.redirect(tT)
- end
- function bufferAPI.setTextColour(nC)
- if type(nC) == "number" then
- bufferAPI.buffer.textColour = bufferAPI.colour.tohex[nC]
- return bufferAPI.term.setTextColour(nC)
- elseif type(nC) == "string" then
- bufferAPI.buffer.textColour = nC
- return bufferAPI.term.setTextColour(bufferAPI.colour.todec[nC])
- end
- end
- function bufferAPI.native()
- return bufferAPI.term.native
- end
- function bufferAPI.getSize()
- return bufferAPI.buffer.width , bufferAPI.buffer.height
- end
- function bufferAPI.write(sText)
- for i=1,#sText do
- if bufferAPI.main[bufferAPI.buffer.cursorY][bufferAPI.buffer.cursorX+i-1] then
- bufferAPI.main[bufferAPI.buffer.cursorY][bufferAPI.buffer.cursorX+i-1] = bufferAPI.buffer.textColour .. bufferAPI.buffer.backColour .. sText:sub(i,i)
- end
- end
- bufferAPI.buffer.cursorX = bufferAPI.buffer.cursorX + #sText
- return bufferAPI.term.write(sText)
- end
- function bufferAPI.setCursorPos(nX,nY)
- bufferAPI.buffer.cursorX = nX
- bufferAPI.buffer.cursorY = nY
- return bufferAPI.term.setCursorPos(nX,nY)
- end
- function bufferAPI.clear()
- for y=1,bufferAPI.buffer.height do
- bufferAPI.main[y] = {}
- for x=1,bufferAPI.buffer.width do
- bufferAPI.main[y][x] = bufferAPI.buffer.textColour .. bufferAPI.buffer.backColour .. " "
- end
- end
- end
- function bufferAPI.setCursorBlink(bA)
- return bufferAPI.term.setCursorBlink(bA)
- end
- function bufferAPI.blit(sText,sTextC,sBackC)
- if not ((#sTextC == #sText) and (#sBackC == #sTextC)) then
- error("Arguments must be the same length")
- end
- for i=1,#sText do
- if bufferAPI.main[bufferAPI.buffer.cursorY][bufferAPI.buffer.cursorX+i-1] then
- bufferAPI.main[bufferAPI.buffer.cursorY][bufferAPI.buffer.cursorX+i-1] = sTextC:sub(i,i) .. sTextB:sub(i,i) .. sText:sub(i,i)
- end
- end
- bufferAPI.buffer.cursorX = bufferAPI.buffer.cursorX + #sText
- return bufferAPI.term.blit(sText,sTextC,sBackC)
- end
- function bufferAPI.setBackgroundColour(nC)
- if type(nC) == "number" then
- bufferAPI.buffer.backColour = bufferAPI.colour.tohex[nC]
- return bufferAPI.term.setBackgroundColour(nC)
- elseif type(nC) == "string" then
- bufferAPI.buffer.backColour = nC
- return bufferAPI.term.setBackgroundColour(bufferAPI.colour.todec[nC])
- end
- end
- function bufferAPI.clearLine()
- for x=1,bufferAPI.buffer.width do
- bufferAPI.main[bufferAPI.buffer.cursorY][x] = bufferAPI.buffer.textColour .. bufferAPI.buffer.backColour .. " "
- end
- return buffer.term.clearLine()
- end
- function bufferAPI.isColour()
- return buffer.term.isColour()
- end
- bufferAPI.isColor = bufferAPI.isColour
- bufferAPI.setTextColor = bufferAPI.setTextColour
- bufferAPI.getTextColor = bufferAPI.getTextColor
- bufferAPI.setBackgroundColor = bufferAPI.setBackgroundColour
- bufferAPI.getBackgroundColor = bufferAPI.getBackgroundColor
- -- Generation
- bufferAPI.main = {}
- for y=1,bufferAPI.buffer.height do
- bufferAPI.main[y] = {}
- for x=1,bufferAPI.buffer.width do
- bufferAPI.main[y][x] = bufferAPI.buffer.textColour .. bufferAPI.buffer.backColour .. " "
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement