2024-06-01 22:52:58 +00:00
|
|
|
local backingList = {}
|
2024-06-01 23:39:01 +00:00
|
|
|
local length = 0
|
2024-06-01 22:52:58 +00:00
|
|
|
local paginationOffset = 1
|
|
|
|
local frame = term.current()
|
|
|
|
local drawLine = nil
|
|
|
|
|
|
|
|
local function setTerm(termlike)
|
|
|
|
frame = termlike
|
|
|
|
end
|
|
|
|
|
|
|
|
local function setDrawLineFunc(drawLineFunc)
|
|
|
|
drawLine = drawLineFunc
|
|
|
|
end
|
|
|
|
|
|
|
|
local function redrawLine(idx)
|
2024-06-01 23:52:02 +00:00
|
|
|
local tw, th = frame.getSize()
|
|
|
|
if idx >= paginationOffset and idx-paginationOffset <= th then
|
2024-06-02 00:02:47 +00:00
|
|
|
frame.setCursorPos(1, idx-paginationOffset+1)
|
2024-06-01 23:52:02 +00:00
|
|
|
frame.setBackgroundColor(colors.red)
|
|
|
|
frame.clearLine()
|
|
|
|
frame.setBackgroundColor(colors.black)
|
|
|
|
if drawLine then
|
2024-06-01 22:52:58 +00:00
|
|
|
drawLine(frame, backingList[idx])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function itemAt(idx)
|
|
|
|
return backingList[idx]
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updateItemAt(idx, item)
|
|
|
|
backingList[idx] = item
|
2024-06-01 23:39:01 +00:00
|
|
|
if idx > length then
|
|
|
|
length = idx
|
|
|
|
end
|
2024-06-01 22:52:58 +00:00
|
|
|
redrawLine(idx)
|
|
|
|
end
|
|
|
|
|
2024-06-02 01:25:04 +00:00
|
|
|
local function clearFrom(idx)
|
2024-06-01 23:39:01 +00:00
|
|
|
local tw, th = frame.getSize()
|
2024-06-02 01:25:04 +00:00
|
|
|
for j = length, idx, -1 do
|
2024-06-01 23:39:01 +00:00
|
|
|
backingList[j] = nil
|
|
|
|
end
|
|
|
|
length = idx
|
2024-06-02 01:25:04 +00:00
|
|
|
for y = idx-paginationOffset+1, th, 1 do
|
2024-06-01 23:39:01 +00:00
|
|
|
frame.setCursorPos(1, y)
|
|
|
|
frame.clearLine()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-01 22:52:58 +00:00
|
|
|
local function redraw()
|
|
|
|
if drawLine then
|
|
|
|
local tw, th = frame.getSize()
|
|
|
|
local backingIdx = paginationOffset
|
|
|
|
for idx = 1, th, 1 do
|
2024-06-02 00:08:55 +00:00
|
|
|
frame.setCursorPos(1, idx)
|
|
|
|
if backingList[backingIdx] == nil then
|
|
|
|
frame.clearLine()
|
|
|
|
else
|
2024-06-01 22:52:58 +00:00
|
|
|
drawLine(frame, backingList[backingIdx])
|
|
|
|
end
|
2024-06-02 00:08:55 +00:00
|
|
|
backingIdx = backingIdx + 1
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function updatePage(newOffset)
|
|
|
|
if newOffset ~= paginationOffset then
|
|
|
|
paginationOffset = newOffset
|
|
|
|
redraw()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
setTerm=setTerm,
|
|
|
|
setDrawLineFunc=setDrawLineFunc,
|
|
|
|
itemAt=itemAt,
|
|
|
|
updateItemAt=updateItemAt,
|
2024-06-02 01:25:04 +00:00
|
|
|
clearFrom=clearFrom,
|
2024-06-01 22:52:58 +00:00
|
|
|
redraw=redraw,
|
|
|
|
updatePage=updatePage,
|
|
|
|
}
|