So here is my code. I know, it is quiet messy because of my minor Lua skills and the experiments to write it down in two columns.
I hope you will understand it despite of german
P.S.: sauber() is a function which clears my terminal
function anzeigen(db, von, bis, mitk)
local _, tast, x, y, maxY
local maxY = false
local maxX = 0
local einrueck = 0
local count = 1
local w, h = term.getSize()
local tmp = {}
local inter = {
["TOP"] = "Verwendung: mit Pfeil hoch/runter navigieren, mit \"Esc\" verlassen.",
["TRENN"] = "-",
}
local function show()
if count > bis then
count = von
elseif count < von then
count = bis
end
sauber()
print(inter["TOP"].."\n"..count.."/"..#tmp.."\n")
local function aufloesung(tab)
einrueck = einrueck + 1
local einrueck = einrueck
for k, v in pairs(tab) do
x, y = term.getCursorPos()
if x > maxX then maxX = x end
if y == h - 2 then
y = 5
maxY = true
end
if maxy == true then einrueck = x + 10 end
if type(v) == "table" then
if mitk then
term.setCursorPos(einrueck,y + 1)
term.write(k)
end
aufloesung(v)
else
term.setCursorPos(einrueck,y + 1)
term.write(tostring(k).." - "..tostring(v))
end
end
end
aufloesung(tmp[count])
for i = 1, w do
if maxY then
term.setCursorPos(i, h)
else
term.setCursorPos(i, y + 2)
end
term.write(inter["TRENN"])
end
end
for k, v in pairs(db) do
tmp[count] = {[k] = v}
count = count + 1
end
if type(von) == "boolean" then
mitk = von
von = 1
elseif type(bis) == "boolean" then
mitk = bis
bis = #tmp
end
von = von or 1
bis = bis or #tmp
if von > bis then
print("Der Startwert muss kleiner sein, als der Endwert!")
print("Die Datenbank wird vom ersten Wert ausgehend angezeigt...")
von = 1
elseif von > #tmp then
print("Die Datenbank endet vor dem angegebenen Startwert!")
print("Die Datenbank wird vom ersten Wert ausgehend angezeigt...")
von = 1
end
if bis > #tmp then
print("Die Datenbank endet vor dem angegebenen Endwert!")
print("Die Datenbank wird bis zum Ende angezeigt...")
bis = #tmp
end
show()
while true do
_, tast = os.pullEvent("key")
if tast == 200 then
count = count - 1
elseif tast == 208 then
count = count + 1
elseif tast == 1 then
sauber()
return
end
einrueck = 0
maxX = 0
maxY = false
show()
end
end