Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local logFile = "me_log.txt" -- Log file for storing output
- local device = peripheral.find("meBridge")
- if not device then
- print("No peripheral found on!")
- return
- end
- local side = peripheral.getName(device)
- local methods = peripheral.getMethods(side)
- if not methods or #methods == 0 then
- print("No functions found for this peripheral.")
- return
- end
- local pageSize = 10 -- Number of methods per page
- local scrollOffset = 0
- local selectedIndex = nil
- -- Number of lines before the list starts (title & spacing)
- local TITLE_OFFSET = 2
- -- Function to display methods
- local function displayMethods()
- term.clear()
- term.setCursorPos(1,1)
- print("Select a function (Scroll with Mouse, Click to Select):\n")
- for i = 1, pageSize do
- local index = i + scrollOffset
- if index > #methods then break end
- if selectedIndex == index then
- term.setTextColor(colors.yellow)
- end
- print(index .. ". " .. methods[index])
- term.setTextColor(colors.white) -- Reset color
- end
- print("\nScroll Up/Down to navigate. Click to select.")
- end
- displayMethods()
- while true do
- local event, button, x, y = os.pullEvent()
- if event == "mouse_scroll" then
- if button == 1 and scrollOffset + pageSize < #methods then
- scrollOffset = scrollOffset + 1
- elseif button == -1 and scrollOffset > 0 then
- scrollOffset = scrollOffset - 1
- end
- displayMethods()
- elseif event == "mouse_click" then
- local methodIndex = y - TITLE_OFFSET -- 🔹 Correctly adjust for title lines
- methodIndex = methodIndex + scrollOffset -- 🔹 Adjust for scrolling
- if methodIndex >= 1 and methodIndex <= #methods then
- selectedIndex = methodIndex
- break
- end
- end
- end
- local selectedMethod = methods[selectedIndex]
- term.clear()
- term.setCursorPos(1,1)
- print("Running: " .. selectedMethod .. "()\n")
- -- Attempt to run the selected function
- local success, result = pcall(device[selectedMethod])
- -- Process result
- local outputLines = {}
- if success then
- if type(result) == "table" then
- local serialized = textutils.serialize(result)
- for line in serialized:gmatch("[^\r\n]+") do
- table.insert(outputLines, line)
- end
- else
- table.insert(outputLines, tostring(result))
- end
- else
- table.insert(outputLines, "Error: Function requires arguments or failed to execute.")
- end
- -- Save outputLines to log file
- local file = fs.open(logFile, "w") -- Open log file for writing
- for _, line in ipairs(outputLines) do
- file.writeLine(line)
- end
- file.close()
- print("\nLog saved to " .. logFile)
- -- Upload log file to Pastebin
- print("\nUploading to Pastebin...")
- local success = shell.run("pastebin", "put", logFile)
- if success then
- print("\nPastebin upload successful!")
- else
- print("\nPastebin upload failed. Ensure you have an internet connection.")
- end
- -- Exit the script immediately
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement