Skip to content

Instantly share code, notes, and snippets.

@AmandaCameron
Created May 15, 2015 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmandaCameron/c2c46c8083d6bdea677e to your computer and use it in GitHub Desktop.
Save AmandaCameron/c2c46c8083d6bdea677e to your computer and use it in GitHub Desktop.
os.loadAPI("__LIB__/veek/veek")
veek.load_api("__LIB__/veek/gui")
local Method = {}
function Method:init(name, data)
self.veek_list_item:init('')
self.name = name
self.data = data
self.source = data.source
end
function Method:draw(canvas)
canvas:clear()
canvas:move(1, 1)
canvas:write(self.name)
canvas:set_fg('grey')
canvas:write("(")
local tmp = {}
for _, arg in pairs(self.data.args) do
local str = arg.name
if arg.vararg then str = arg.name .. "..."
elseif arg.optional then str = arg.name .. "?" end
table.insert(tmp, str)
end
if #tmp > 0 then
canvas:write(table.concat(tmp, ", "))
end
canvas:write(")")
canvas:move(canvas.width - #self.source - 1, 1)
canvas:write(' ' .. self.source)
end
kidven.register("opd-method", Method, 'veek-list-item')
local args = { ... }
local app = kidven.new("veek-app")
local layout = kidven.new('veek-layout', app.main_window)
local methods = kidven.new('veek-search', term.getSize())
layout:add(methods)
layout:add_anchor(methods, 'top', 'top', -1, 0)
layout:add_anchor(methods, 'left', 'left', -1, 0)
layout:add_anchor(methods, 'right', 'right', -1, 0)
layout:add_anchor(methods, 'bottom', 'bottom', -1, 0)
layout:reflow()
local p = peripheral.wrap(args[1])
if not p.getAdvancedMethodsData then
print("Peripheral is not an OpenP Peripheral")
return
end
local info = p.getAdvancedMethodsData()
app:subscribe('gui.search.input', function(_, id, terms)
methods.results:clear()
terms = terms:lower()
for name, data in pairs(info) do
if name:lower():find(terms) or data.source:lower():find(terms) then
local item = kidven.new('opd-method', name, data)
methods.results:add(item)
end
end
end)
app:subscribe('gui.search.selected', function(_, id, item)
local window = app:new_window(item.name, 35, 12)
local textbox = kidven.new('veek-textbox', 1, 1, 35, 12)
window:add_flag('closable')
window:add(textbox)
local text = ''
text = text .. item.name .. ' from ' .. item.data.source
text = text .. '\n ' .. item.data.description
text = text .. '\n\n Arguments:'
if #item.data.args > 0 then
for _, arg in ipairs(item.data.args) do
text = text .. '\n - ' .. arg.type:lower() .. ' ' .. arg.name
if arg.vararg then text = text .. '...' end
if arg.optional then text = text .. '?' end
text = text .. ': ' .. arg.description
end
else
text = text .. ' None'
end
app:subscribe('window.closed', function(_, id)
if id == window.id then
window:hide()
app:select(methods)
end
end)
textbox:set_text(text)
window:select(textbox)
end)
app:main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment