local event = require "event" local sides = require "sides" local inv = require "inv" local mtmenu = require "mtmenu" local stat = "" function inv.search(searchterm) local rt repeat rt = inv.matchAll({label=searchterm or ""},true) if not rt then mtmenu.popup("Server appears to be down.\nPress any key to try again.","Error") event.pull("key_down") end until rt return rt, #rt, #rt end local searchterm = "" --local output = inv.getAliases()[os.getenv("HOSTNAME")] local output local ci,si = 1,1 local run = true local timers = {} repeat local w,aliases = pcall(inv.getAliases) if not w then mtmenu.popup("Server appears to be down.\nPress any key to try again.","Error") event.pull("key_down") else output=aliases[os.getenv("HOSTNAME")] end until w local phases = { [0] = "⣿⣿", "⢾⣿", " ⣿", " ⣹", "⣏⣹", "⣏ ", "⣿ ", "⣿⡷" } local function search() io.write("\n\27[2KSearch: ") searchterm = io.read() end local function setOutput() io.write("\n\27[2KOutput side:") local ins = io.read() output = tonumber(ins) or sides[ins] end local function extract(item) io.write(string.format("\nExtracting %s; Count [64] or x to exit? ",item.label)) local count = io.read() if count == "x" then return false end count=tonumber(count) or 64 item.size = nil local w, c = inv.extract(item,count,output[1],output[2]) mtmenu.setStatus(string.format("%s: %i items extracted", w and "Success" or "Error", c or 0)) end local function info(item) local s = string.format("\n%s (%s)\nCount: %d\n",item.label,item.name,item.size) if item.aspects then s=s.."Aspects: " for k,v in pairs(item.aspects) do s=string.format("%s\n - %d x %s",s,v,k) end end s=s.."\n\nPress any key." mtmenu.popup(s,item.label or item.name) event.pull("key_down") end local function help() mtmenu.popup("\n[Tab] Search\n[Enter] Extract Items\n[i] Item Information\n[r] Refresh\n[o] Set output\n\nPress any key.","Key bindings") event.pull("key_down") end local function formatEntries(t,used,size,searchterm) local rt = {} local mx, my = mtmenu.getScreenSize() rt.header = " Name" .. (" "):rep(mx-11) .. "Count" rt.status = string.format(" %s (%i/%i) %s %s", phases[math.floor((os.time()-43200)/86400)%8], used, size, searchterm):sub(1,mx):sub(1,mx-7) .. "[H]elp" for k,v in ipairs(t) do -- (YYxYY+NN) local count = string.format("(%ix%i+%i)",v.size//v.maxSize, v.maxSize, v.size%v.maxSize) local fmt = string.format("%%-%is %%s", mx-#count-1) rt[k] = string.format(fmt, v.label, count) end return rt end while run do local sr, used, size = inv.search(searchterm) local ci, ch, co, st while true do ci, ch, co, st = mtmenu.menu(formatEntries(sr,used,size,searchterm), st) if co == 28 then -- enter extract(sr[ci]) break elseif co == 15 then -- tab search() break elseif ch == "i" then info(sr[ci]) elseif ch == "h" then help() elseif ch == "r" then mtmenu.popup("Refreshing index...") break elseif ch == "o" then setOutput() elseif ch == "q" then run = false break end end end for k,v in pairs(timers) do event.cancel(v) end