[inspect] draw key value visually separated

This commit is contained in:
Ben 2024-06-02 23:03:19 +02:00
parent 64bd641528
commit 4a75b24d32
Signed by: ben
GPG key ID: 0F54A7ED232D3319

View file

@ -1,4 +1,6 @@
local listview = require "listview" local listview = require "listview"
local winhlp = require "winhlp"
local keys = {[1]="a", [2]="c"} local keys = {[1]="a", [2]="c"}
local obj = {a="b", c="d"} local obj = {a="b", c="d"}
local frame = term.current() local frame = term.current()
@ -20,7 +22,7 @@ end
local function fetch(wait_for) local function fetch(wait_for)
local currentIdx = 1 local currentIdx = 1
for i, key in pairs(keys) do for i, key in pairs(keys) do
listview.updateItemAt(currentIdx, tostring(key)..": "..tostring(obj[key])) listview.updateItemAt(currentIdx, {key=key, value=obj[key]})
currentIdx = currentIdx + 1 currentIdx = currentIdx + 1
end end
listview.clearFrom(currentIdx) listview.clearFrom(currentIdx)
@ -34,10 +36,16 @@ local function estimatedHeight()
return #keys return #keys
end end
local function drawLine(termlike, line) local function drawLine(termlike, pair)
termlike.setBackgroundColor(colors.black) termlike.setBackgroundColor(colors.black)
termlike.setTextColor(colors.yellow)
termlike.write(tostring(pair.key))
termlike.setTextColor(colors.white) termlike.setTextColor(colors.white)
termlike.write(line) local value = tostring(pair.value)
local padding = winhlp.alignRightPadding(termlike, #value + 1)
termlike.write(string.format("%" .. padding .. "s", " "))
termlike.write(value)
end end
listview.setDrawEntryFunc(drawLine) listview.setDrawEntryFunc(drawLine)