goldfiction

perihelp

Aug 10th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local argv = {...}
  2.  
  3. if not argv[1] then
  4.     print("Usage:\nperihelp [side/device]");
  5.     return
  6. end
  7.  
  8. local p = peripheral.wrap(argv[1])
  9.  
  10. if not p then
  11.     print("Cannot wrap peripheral!")
  12.     return
  13. end
  14.  
  15. if not p.getAdvancedMethodsData then
  16.     print("Peripheral Does not support\ngetAdvancedMethodsData!")
  17.     return
  18. end
  19.  
  20. local data = p.getAdvancedMethodsData()
  21. local lines = {}
  22.  
  23. if not data then
  24.     print("No Data!")
  25.     return
  26. end
  27.  
  28.  
  29. local function writeln(str)
  30.     lines[#lines+1] = str
  31. end
  32. writeln("")
  33. for fk, fn in ipairs(data) do
  34.     local fname = ":o" .. fn.name .. "("
  35.    
  36.     for ak, a in ipairs(fn.args) do
  37.         fname = fname .. a.name .. ","
  38.     end
  39.    
  40.     if #fn.args > 0 then fname = fname:sub(1,#fname - 1) end
  41.     fname = fname .. ")"
  42.     writeln(fname)
  43.     writeln("")
  44.     writeln(" "..fn.description)
  45.     writeln("")
  46.     writeln(":l Returns "..fn.returnType)
  47.    
  48.     for ak, a in ipairs(fn.args) do
  49.         writeln(" :lArgument "..tostring(ak).." ("..a.name..")::")
  50.         writeln("  :gType:: :w"..a.type)
  51.         writeln("  "..a.description)
  52.     end
  53.    
  54.     writeln(":q---------------")
  55. end
  56.  
  57. ---------------
  58. --SysX MAN engine start
  59.  
  60. local aln = 1
  61.  
  62. local function rLine(lid)
  63.     if lines[lid] then
  64.         local ti = 0
  65.         while ti < #(lines[lid]) do
  66.             ti = ti + 1
  67.             if lines[lid]:sub(ti,ti) == ":" then
  68.                 local op = lines[lid]:sub(ti+1,ti+1)
  69.                 ti = ti + 1
  70.                 if op == ":" then
  71.                     write(":");
  72.                 elseif op == "w" then
  73.                     term.setTextColor(colors.white)
  74.                 elseif op == "o" then
  75.                     term.setTextColor(colors.orange)
  76.                 elseif op == "m" then
  77.                     term.setTextColor(colors.magenta)
  78.                 elseif op == "l" then
  79.                     term.setTextColor(colors.lime)
  80.                 elseif op == "p" then
  81.                     term.setTextColor(colors.pink)
  82.                 elseif op == "a" then
  83.                     term.setTextColor(colors.gray)
  84.                 elseif op == "c" then
  85.                     term.setTextColor(colors.cyan)
  86.                 elseif op == "q" then
  87.                     term.setTextColor(colors.purple)
  88.                 elseif op == "n" then
  89.                     term.setTextColor(colors.brown)
  90.                 elseif op == "g" then
  91.                     term.setTextColor(colors.green)
  92.                 elseif op == "r" then
  93.                     term.setTextColor(colors.red)
  94.                 elseif op == "b" then
  95.                     term.setTextColor(colors.black)
  96.                    
  97.                 elseif op == "W" then
  98.                     term.setBackgroundColor(colors.white)
  99.                 elseif op == "O" then
  100.                     term.setBackgroundColor(colors.orange)
  101.                 elseif op == "M" then
  102.                     term.setBackgroundColor(colors.magenta)
  103.                 elseif op == "L" then
  104.                     term.setBackgroundColor(colors.lime)
  105.                 elseif op == "P" then
  106.                     term.setBackgroundColor(colors.pink)
  107.                 elseif op == "A" then
  108.                     term.setBackgroundColor(colors.gray)
  109.                 elseif op == "C" then
  110.                     term.setBackgroundColor(colors.cyan)
  111.                 elseif op == "Q" then
  112.                     term.setBackgroundColor(colors.purple)
  113.                 elseif op == "W" then
  114.                     term.setBackgroundColor(colors.brown)
  115.                 elseif op == "G" then
  116.                     term.setBackgroundColor(colors.green)
  117.                 elseif op == "R" then
  118.                     term.setBackgroundColor(colors.red)
  119.                 elseif op == "B" then
  120.                     term.setBackgroundColor(colors.black)
  121.                 else
  122.                     write("!NIMPL!")
  123.                 end
  124.                    
  125.             else
  126.                 write(lines[lid]:sub(ti,ti))
  127.             end
  128.         end
  129.     end
  130.     term.setTextColor(colors.white)
  131.     term.setBackgroundColor(colors.black)
  132. end
  133.  
  134. local sx,sy = term.getSize()
  135.  
  136. local function render()
  137.     term.clear()
  138.     term.setCursorPos(1,1)
  139.     local px,py = term.getCursorPos()
  140.     while py < sy do
  141.         rLine(py+aln-1)
  142.         if px<sy then write("\n") end
  143.         px,py = term.getCursorPos()
  144.     end
  145. end
  146. render()
  147.  
  148. while true do
  149.     local e = {os.pullEvent()}
  150.     if e[1] == "key" then
  151.         if e[2] == 16 then
  152.             os.startTimer(0.2)
  153.             os.pullEvent()
  154.             write("\n")
  155.             return
  156.         elseif e[2] == 200 then
  157.             aln = aln - 1
  158.         elseif e[2] == 208 then
  159.             aln = aln + 1
  160.         elseif e[2] == 203 then
  161.             aln = aln - sy
  162.         elseif e[2] == 205 then
  163.             aln = aln + sy
  164.         end
  165.     elseif e[1] == "mouse_scroll" then
  166.         aln = aln + e[2]
  167.     end
  168.     if aln >= #lines-sy+1 then aln = #lines - sy + 1 end
  169.     if aln < 1 then aln = 1 end
  170.     render()
  171. end
Add Comment
Please, Sign In to add comment