Advertisement
HPWebcamAble

[CC][1.1] Get Methods

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