Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- method decovery
- by BigSHinyToys
- ]]--
- local tab = 1
- local tSide = rs.getSides()
- local width,hight = term.getSize()
- local space = math.floor(width/6)
- local methods = {}
- local function clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorBlink(false)
- term.setCursorPos(1,1)
- end
- local function clearL(y)
- term.setCursorPos(1,y)
- term.clearLine()
- end
- local function clearBox(backCol)
- term.setBackgroundColor(colors[backCol])
- for i = 2,hight do
- clearL(i)
- end
- end
- local function setCol(textCol,backCol)
- term.setTextColor(colors[textCol])
- term.setBackgroundColor(colors[backCol])
- end
- local function printC(posX,posY,textCol,backCol,text)
- term.setCursorPos(posX,posY)
- term.setTextColor(colors[textCol])
- term.setBackgroundColor(colors[backCol])
- term.write(text)
- end
- local function drawTabs()
- for i = 1,6 do
- if i == tab then
- printC((space*(i-1))+1,1,"green","lime","["..tSide[i]..string.rep(" ",space-#tSide[i]-2).."]")
- else
- printC((space*(i-1))+1,1,"blue","lightBlue","["..tSide[i]..string.rep(" ",space-#tSide[i]-2).."]")
- end
- end
- printC(width,1,"white","red","X")
- end
- local function drawData()
- if peripheral.isPresent(tSide[tab]) then
- local pos = 3
- printC(1,2,"green","lime","Peripheral : "..peripheral.getType(tSide[tab]))
- methods = peripheral.getMethods(tSide[tab])
- for i,v in pairs(methods) do
- printC(1,pos,"green","lime",tostring(i).." "..tostring(v))
- pos = pos + 1
- end
- else
- printC(1,2,"green","lime","Peripheral : NIL")
- methods = {}
- end
- end
- clear()
- local lastTab
- local function draw()
- clearBox("lime")
- drawTabs()
- drawData()
- lastTab = tab
- end
- while true do
- if lastTab ~= tab then
- draw()
- end
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- if event[2] == 1 then -- left click
- if event[4] == 1 then -- first line
- for i = 1,6 do
- if event[3] > space*(i-1) and event[3] < (space*(i))+1 then
- tab = i
- end
- end
- if event[3] == width then
- break
- end
- elseif methods[event[4] - 2] and type(methods[event[4] - 2]) == "string" and event[3] < string.len(methods[event[4]-2])+string.len(tostring(event[4] - 2))+1 then
- draw()
- local test = {pcall(peripheral.call,tSide[tab],methods[event[4] - 2])}
- term.setCursorPos(1,hight - 1)
- setCol("red","lightBlue")
- write(tostring(methods[event[4] - 2]).." ")
- for i = 1,#test do
- write(tostring(test[i]).." ")
- end
- end
- end
- elseif event[1] == "peripheral" or event[1] == "peripheral_detach" then
- lastTab = nil
- end
- end
- clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement