53 lines
1.1 KiB
Lua
53 lines
1.1 KiB
Lua
local listview = require "listview"
|
|
local keys = {[1]="a", [2]="c"}
|
|
local obj = {a="b", c="d"}
|
|
local frame = term.current()
|
|
|
|
local function setTerm(termlike)
|
|
frame = termlike
|
|
listview.setTerm(frame)
|
|
end
|
|
|
|
local function setObject(other)
|
|
obj = other
|
|
keys = {}
|
|
for key, _ in other do
|
|
keys.insert(key)
|
|
end
|
|
table.sort(keys)
|
|
end
|
|
|
|
local function fetch(wait_for)
|
|
local currentIdx = 1
|
|
for i, key in pairs(keys) do
|
|
listview.updateItemAt(currentIdx, tostring(key)..": "..tostring(obj[key]))
|
|
currentIdx = currentIdx + 1
|
|
end
|
|
listview.clearFrom(currentIdx)
|
|
end
|
|
|
|
local function displayTab(self)
|
|
listview.updatePage(self.scrollPos)
|
|
end
|
|
|
|
local function estimatedHeight()
|
|
return #keys
|
|
end
|
|
|
|
local function drawLine(termlike, line)
|
|
termlike.setBackgroundColor(colors.black)
|
|
termlike.setTextColor(colors.white)
|
|
termlike.write(line)
|
|
end
|
|
listview.setDrawEntryFunc(drawLine)
|
|
|
|
|
|
return {
|
|
name="inspect",
|
|
setTerm=setTerm,
|
|
setObject=setObject,
|
|
fetch=fetch,
|
|
displayTab=displayTab,
|
|
estimatedHeight=estimatedHeight,
|
|
}
|