diff --git a/listview.lua b/listview.lua index 396f9cf..e9e96c6 100644 --- a/listview.lua +++ b/listview.lua @@ -1,4 +1,5 @@ local backingList = {} +local length = 0 local paginationOffset = 1 local frame = term.current() local drawLine = nil @@ -27,9 +28,24 @@ end local function updateItemAt(idx, item) backingList[idx] = item + if idx > length then + length = idx + end redrawLine(idx) end +local function clearAfter(idx) + local tw, th = frame.getSize() + for j = length, idx+1, -1 do + backingList[j] = nil + end + length = idx + for y = paginationOffset-idx+2, th, 1 do + frame.setCursorPos(1, y) + frame.clearLine() + end +end + local function redraw() if drawLine then local tw, th = frame.getSize() @@ -56,6 +72,7 @@ return { setDrawLineFunc=setDrawLineFunc, itemAt=itemAt, updateItemAt=updateItemAt, + clearAfter=clearAfter, redraw=redraw, updatePage=updatePage, }