diff --git a/libs/ui/CountersSelector.lua b/libs/ui/CountersSelector.lua index 37ef2bb..9d71122 100644 --- a/libs/ui/CountersSelector.lua +++ b/libs/ui/CountersSelector.lua @@ -57,9 +57,9 @@ end local TITLE_MARGIN = 1 -local function renderCountersMap(countersMap, selectedCounter, titleFn) - term.setCursorPos(1, 1) - local _, height = term.getSize() +local function renderCountersMap(win, countersMap, selectedCounter, titleFn) + win.setCursorPos(1, 1) + local _, height = win.getSize() -- local nbCounters = utils.sizeof(countersMap) -- local totalCount = getTotalCount(countersMap) @@ -67,8 +67,7 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn) local bottomMargin = 0 if titleFn ~= noTitleFn then - term.clearLine() - term.write('custom title: ' .. titleFn(countersMap, selectedCounter)) + win.write('custom title: ' .. titleFn(countersMap, selectedCounter)) topMargin = TITLE_MARGIN end @@ -82,18 +81,17 @@ local function renderCountersMap(countersMap, selectedCounter, titleFn) local cursorYIndex = 1 + topMargin for k,v in pairs(displayedCounters) do - term.setCursorPos(1, cursorYIndex) - term.clearLine() + win.setCursorPos(1, cursorYIndex) if k == selectedCounter then - term.setBackgroundColor(colors.white) - term.setTextColor(colors.black) + win.setBackgroundColor(colors.white) + win.setTextColor(colors.black) else - term.setBackgroundColor(colors.black) - term.setTextColor(colors.white) + win.setBackgroundColor(colors.black) + win.setTextColor(colors.white) end - term.write(tostring(v.name) .. ' ' .. tostring(v.count)) + win.write(tostring(v.name) .. ' ' .. tostring(v.count)) cursorYIndex = cursorYIndex + 1 end end @@ -111,8 +109,7 @@ local function CountersSelector(initialCountersMap, config) error('empty countersMap provided') end - saveTermConfig() - term.clear() + -- saveTermConfig() local selectedCounter = 1 local nbCounters = utils.sizeof(countersMap) @@ -122,9 +119,18 @@ local function CountersSelector(initialCountersMap, config) error('counter cannot be greater than the counterMax') end + local topHeight = 0 + if titleFn ~= noTitleFn then + topHeight = 1 + end + + term.clear() + local mainWin = window.create(term.current(), 1, 1 + topHeight, width, height - topHeight) + local shouldContinue = true while shouldContinue do - renderCountersMap(countersMap, selectedCounter, titleFn) + mainWin.clear() + renderCountersMap(mainWin, countersMap, selectedCounter, titleFn) local _, keyPressed, isHeld = os.pullEvent('key') if keyPressed == keys.up then @@ -154,7 +160,7 @@ local function CountersSelector(initialCountersMap, config) end end - restoreTermConfig() + -- restoreTermConfig() return countersMap, selectedCounter end