Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if #args == 0 then
- error("Usage: apibrowser <peripheral>")
- end
- local pName = args[1]
- local p = peripheral.wrap(pName)
- local sizeX, sizeY = term.getSize()
- local sel = 1
- local methods = peripheral.getMethods(pName)
- function draw()
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clearLine()
- term.write(pName .. " (" .. #peripheral.getMethods(pName) .. ")")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- local y = 2
- while y < sizeY - 8 do
- local i = y - 3 + sel
- term.setCursorPos(1, y)
- if y == 3 then
- term.write("> ")
- else
- term.write(" ")
- end
- if i >= 1 and i <= #methods then
- term.write(methods[i])
- end
- y = y + 1
- end
- if p.doc then
- term.setCursorPos(1, sizeY - 8)
- print(p.doc(methods[sel]))
- end
- end
- draw()
- while true do
- local event = {os.pullEvent()}
- if event[1] == "key" then
- if event[2] == 208 then
- if sel < #methods then
- sel = sel + 1
- end
- elseif event[2] == 200 then
- if sel > 1 then
- sel = sel - 1
- end
- end
- elseif event[1] == "key_up" then
- if event[2] == 16 then
- term.clear()
- term.setCursorPos(1, 1)
- error()
- end
- end
- draw()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement