From 4a75b24d326455366d0d8a2e103f4564e83ab24f Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sun, 2 Jun 2024 23:03:19 +0200 Subject: [PATCH] [inspect] draw key value visually separated --- inspect.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/inspect.lua b/inspect.lua index edb8fb0..6981bca 100644 --- a/inspect.lua +++ b/inspect.lua @@ -1,4 +1,6 @@ local listview = require "listview" +local winhlp = require "winhlp" + local keys = {[1]="a", [2]="c"} local obj = {a="b", c="d"} local frame = term.current() @@ -20,7 +22,7 @@ end local function fetch(wait_for) local currentIdx = 1 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 end listview.clearFrom(currentIdx) @@ -34,10 +36,16 @@ local function estimatedHeight() return #keys end -local function drawLine(termlike, line) +local function drawLine(termlike, pair) termlike.setBackgroundColor(colors.black) + termlike.setTextColor(colors.yellow) + termlike.write(tostring(pair.key)) + 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 listview.setDrawEntryFunc(drawLine)