From 5bbd42d461548c46ecc7fcff6a480aa03e657747 Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sun, 2 Jun 2024 01:39:01 +0200 Subject: [PATCH] Add missing clearAfter to listview --- listview.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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, }