2024-06-01 22:52:58 +00:00
|
|
|
local backingList = {}
|
2024-06-01 23:39:01 +00:00
|
|
|
local length = 0
|
2024-06-02 15:39:21 +00:00
|
|
|
local paginationPos = 1
|
2024-06-01 22:52:58 +00:00
|
|
|
local frame = term.current()
|
2024-06-02 14:41:54 +00:00
|
|
|
local drawEntry = nil
|
2024-06-01 22:52:58 +00:00
|
|
|
|
|
|
|
local function setTerm(termlike)
|
|
|
|
frame = termlike
|
|
|
|
end
|
|
|
|
|
2024-06-02 14:41:54 +00:00
|
|
|
local function setDrawEntryFunc(drawLineFunc)
|
|
|
|
drawEntry = drawLineFunc
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
|
|
|
|
2024-06-02 14:41:54 +00:00
|
|
|
local function redrawEntry(idx)
|
2024-06-01 23:52:02 +00:00
|
|
|
local tw, th = frame.getSize()
|
2024-06-02 15:39:21 +00:00
|
|
|
if idx >= paginationPos and idx-paginationPos <= th then
|
|
|
|
frame.setCursorPos(1, idx-paginationPos+1)
|
2024-06-02 14:41:54 +00:00
|
|
|
if drawEntry then
|
|
|
|
drawEntry(frame, backingList[idx])
|
2024-06-02 02:22:07 +00:00
|
|
|
else
|
|
|
|
frame.setBackgroundColor(colors.red)
|
|
|
|
frame.clearLine()
|
|
|
|
frame.setBackgroundColor(colors.black)
|
2024-06-01 22:52:58 +00:00
|
|
|
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-02 14:41:54 +00:00
|
|
|
redrawEntry(idx)
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
|
|
|
|
2024-06-02 15:51:21 +00:00
|
|
|
local function getLength()
|
|
|
|
return length
|
|
|
|
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 15:39:21 +00:00
|
|
|
for y = idx-paginationPos+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()
|
2024-06-02 14:41:54 +00:00
|
|
|
if drawEntry then
|
2024-06-01 22:52:58 +00:00
|
|
|
local tw, th = frame.getSize()
|
2024-06-02 15:39:21 +00:00
|
|
|
local backingIdx = paginationPos
|
2024-06-01 22:52:58 +00:00
|
|
|
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-02 14:41:54 +00:00
|
|
|
drawEntry(frame, backingList[backingIdx])
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
2024-06-02 00:08:55 +00:00
|
|
|
backingIdx = backingIdx + 1
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
2024-06-02 02:22:07 +00:00
|
|
|
else
|
|
|
|
frame.setBackgroundColor(colors.red)
|
|
|
|
frame.clear()
|
|
|
|
frame.setBackgroundColor(colors.black)
|
2024-06-01 22:52:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-02 15:39:21 +00:00
|
|
|
local function updatePage(scrollPos)
|
|
|
|
if scrollPos ~= paginationPos then
|
|
|
|
paginationPos = scrollPos
|
2024-06-01 22:52:58 +00:00
|
|
|
redraw()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-02 02:22:07 +00:00
|
|
|
local function updatePartial(filter)
|
2024-06-02 14:41:54 +00:00
|
|
|
if drawEntry then
|
2024-06-02 02:22:07 +00:00
|
|
|
local tw, th = frame.getSize()
|
2024-06-02 15:39:21 +00:00
|
|
|
local backingIdx = paginationPos
|
2024-06-02 02:22:07 +00:00
|
|
|
for idx = 1, th, 1 do
|
|
|
|
frame.setCursorPos(1, idx)
|
|
|
|
if backingList[backingIdx] ~= nil and filter(backingList[backingIdx]) then
|
2024-06-02 14:41:54 +00:00
|
|
|
drawEntry(frame, backingList[backingIdx])
|
2024-06-02 02:22:07 +00:00
|
|
|
end
|
|
|
|
backingIdx = backingIdx + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-01 22:52:58 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
setTerm=setTerm,
|
2024-06-02 14:41:54 +00:00
|
|
|
setDrawEntryFunc=setDrawEntryFunc,
|
2024-06-01 22:52:58 +00:00
|
|
|
itemAt=itemAt,
|
|
|
|
updateItemAt=updateItemAt,
|
2024-06-02 15:51:21 +00:00
|
|
|
length=getLength,
|
2024-06-02 01:25:04 +00:00
|
|
|
clearFrom=clearFrom,
|
2024-06-01 22:52:58 +00:00
|
|
|
redraw=redraw,
|
|
|
|
updatePage=updatePage,
|
2024-06-02 02:22:07 +00:00
|
|
|
updatePartial=updatePartial,
|
2024-06-01 22:52:58 +00:00
|
|
|
}
|