SHOW:
|
|
- or go back to the newest paste.
| 1 | --opencomputer : https://pastebin.com/G3YjRgFH | |
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | --[[ | |
| 6 | HPWebcamAble presents... | |
| 7 | Get Methods | |
| 8 | ||
| 9 | === Description ==== | |
| 10 | Dispalys the functions of a periperal | |
| 11 | ||
| 12 | Example: Monitor, Turtle, Printer... | |
| 13 | ||
| 14 | ||
| 15 | ==== Installation and Use ==== | |
| 16 | Pastebin Code: sKLqTGrM | |
| 17 | ||
| 18 | To download a file from pastebin: | |
| 19 | pastebin get <code> <name> | |
| 20 | ||
| 21 | Place computer next to the block you want the methods of | |
| 22 | Run the program with the side of the peripheral as an argument | |
| 23 | ||
| 24 | This displays the functions of | |
| 25 | a peripheral using peirpheral.getMethods(side) | |
| 26 | ||
| 27 | ||
| 28 | ==== Update History ==== | |
| 29 | The pastebin will always have the most recent version | |
| 30 | ||
| 31 | |1.1| <-- This program | |
| 32 | -You can now scroll through the pages with the arrow keys | |
| 33 | -You can use it on the regular (non color) computer now | |
| 34 | -Cleaned up code | |
| 35 | |1.0| | |
| 36 | -Release | |
| 37 | ]] | |
| 38 | ||
| 39 | args = {...}
| |
| 40 | ||
| 41 | --Variables-- | |
| 42 | local pFunctions | |
| 43 | local w,h = term.getSize() | |
| 44 | ||
| 45 | --Functions-- | |
| 46 | function tc(...) | |
| 47 | if term.isColor() then | |
| 48 | term.setTextColor(...) | |
| 49 | end | |
| 50 | end | |
| 51 | ||
| 52 | function isSide(name) | |
| 53 | local sides = rs.getSides() | |
| 54 | for i = 1, #sides do | |
| 55 | if name == sides[i] then | |
| 56 | return true | |
| 57 | end | |
| 58 | end | |
| 59 | return false | |
| 60 | end | |
| 61 | ||
| 62 | ||
| 63 | --Program-- | |
| 64 | if #args == 0 then | |
| 65 | print("Usages:")
| |
| 66 | print(shell.getRunningProgram().." <side>") | |
| 67 | return | |
| 68 | elseif not isSide(args[1]) then | |
| 69 | printError(args[1].." isn't a valid side") | |
| 70 | return | |
| 71 | elseif not peripheral.isPresent(args[1]) then | |
| 72 | printError("There is no peripheral on that side")
| |
| 73 | return | |
| 74 | end | |
| 75 | ||
| 76 | term.setCursorPos(1,1) | |
| 77 | term.clear() | |
| 78 | tc(colors.yellow) | |
| 79 | local heading = "Functions for '"..peripheral.getType(args[1]).."' (Located on the "..args[1]..")" | |
| 80 | local hLines = print(heading)+1 | |
| 81 | tc(colors.white) | |
| 82 | ||
| 83 | local pFunctions = peripheral.getMethods(args[1]) | |
| 84 | local pages = math.ceil(#pFunctions/(h-hLines)) | |
| 85 | local fPerPage = math.floor(#pFunctions/pages) | |
| 86 | local cPage = 1 | |
| 87 | ||
| 88 | if pages > 1 then | |
| 89 | while true do | |
| 90 | for i = 1, h-hLines do | |
| 91 | local curF = i+fPerPage*(cPage-1) | |
| 92 | if curF > #pFunctions then break end | |
| 93 | term.setCursorPos(1,hLines+i-1) | |
| 94 | term.write(pFunctions[curF]) | |
| 95 | end | |
| 96 | term.setCursorPos(1,h) | |
| 97 | if cPage == 1 then | |
| 98 | tc(colors.yellow) | |
| 99 | term.write("Use arrow keys to navagate < Back / Forward >")
| |
| 100 | tc(colors.white) | |
| 101 | elseif cPage < pages then | |
| 102 | tc(colors.yellow) | |
| 103 | term.write("< Back / Forward >")
| |
| 104 | tc(colors.white) | |
| 105 | else | |
| 106 | tc(colors.yellow) | |
| 107 | term.write("< Back / Exit >")
| |
| 108 | tc(colors.white) | |
| 109 | end | |
| 110 | local continue = true | |
| 111 | while continue do | |
| 112 | local event,key = os.pullEvent("key")
| |
| 113 | if key == keys.right then | |
| 114 | if cPage < pages then | |
| 115 | cPage = cPage+1 | |
| 116 | break | |
| 117 | else | |
| 118 | term.setCursorPos(1,h) | |
| 119 | tc(colors.yellow) | |
| 120 | term.write("Press > (Right) to exit, or < (Left) to cancel")
| |
| 121 | tc(colors.white) | |
| 122 | while true do | |
| 123 | local event1,key1 = os.pullEvent("key")
| |
| 124 | if key1 == keys.right then | |
| 125 | term.setCursorPos(1,h) | |
| 126 | term.clearLine() | |
| 127 | term.setCursorPos(1,math.ceil(#pFunctions/pages)+hLines) | |
| 128 | error() | |
| 129 | elseif key1 == keys.left then | |
| 130 | continue = false | |
| 131 | break | |
| 132 | end | |
| 133 | end | |
| 134 | end | |
| 135 | elseif key == keys.left then | |
| 136 | if cPage > 1 then | |
| 137 | cPage = cPage-1 | |
| 138 | break | |
| 139 | end | |
| 140 | end | |
| 141 | end | |
| 142 | term.setCursorPos(1,1) | |
| 143 | term.clear() | |
| 144 | tc(colors.yellow) | |
| 145 | print(heading) | |
| 146 | tc(colors.white) | |
| 147 | end | |
| 148 | else | |
| 149 | for a,b in pairs(pFunctions) do | |
| 150 | print(b) | |
| 151 | end | |
| 152 | end |