Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local page = {}
- function page.getPos(self)
- for y=1,self.h do
- for x=1,self.w do
- if self[x][y][1] == nil then
- return x,y
- end
- end
- end
- end
- function page.draw(self,words,x,y,txt,back)
- txt = txt or self.deftext
- back = back or self.defback
- for i = 0,#words-1 do
- if not (x + i > self.w) then
- self[x + i][y] = {words:sub(i+1,i+1),txt,back}
- end
- end
- if x + #words > self.w then
- self.x = 1
- self.y = y + 1
- else
- self.x = x + #words
- self.y = y
- end
- end
- function page.write(self,words,txt,back)
- local x,y = self.x,self.y
- txt = txt or self.deftxt
- back = back or self.defback
- for i = 0,#words-1 do
- if not (x + i > self.w) then
- self[x + i][y] = {words:sub(i+1,i+1),txt,back}
- end
- end
- if x + #words > self.w then
- self.x = 1
- self.y = y + 1
- else
- self.x = x + #words
- self.y = y
- end
- end
- function page.print(self,words,txt,back)
- local x,y = self:getPos()
- txt = txt or self.deftxt
- back = back or self.defback
- for i = 0,#words-1 do
- if not (x + i > self.w) then
- self[x + i][y] = {words:sub(i+1,i+1),txt,back}
- end
- end
- self.x = 1
- self.y = y + 1
- end
- function page.render(self,w,h)
- term.setBackgroundColor(self.defback)
- term.clear()
- local txtcol = self.deftxt
- local backcol = self.defback
- if not (w and h) then
- w,h = term.getSize()
- end
- for y = 1,h do
- for x = 1,w do
- if self[x][y][1] then
- term.setCursorPos(x,y)
- if self[x][y][2] ~= txtcol then
- term.setTextColor(self[x][y][2])
- txtcol = self[x][y][2]
- end
- if self[x][y][3] ~= backcol then
- term.setBackgroundColor(self[x][y][3])
- txtcol = self[x][y][3]
- end
- write(self[x][y][1])
- end
- end
- end
- end
- function createPage(w,h)
- if not (w and h) then
- w,h = term.getSize()
- end
- local buffer = {}
- for x = 1,w do
- buffer[x] = {}
- for y = 1,h do
- buffer[x][y] = {}
- end
- end
- buffer.x = 1
- buffer.y = 1
- buffer.w = w
- buffer.h = h
- buffer.deftxt = colors.white
- buffer.defback = colors.black
- for i,v in pairs(page) do
- buffer[i] = v
- end
- return buffer
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement