Advertisement
BigSHinyToys

test ver of splitter mk3 non release ver

Mar 19th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. --[[
  2.         Display - program for managing terminal redirect
  3.         By BigShinyToys
  4. ]]--
  5.  
  6. print("locating screens")
  7. local function grabScreens()
  8.     local tScreen = {}
  9.     for _,side in pairs(rs.getSides()) do
  10.         if peripheral.isPresent(side) then
  11.             local sType = peripheral.getType(side)
  12.             if sType == "monitor" then
  13.                 table.insert(tScreen,{["type"] = "direct",["side"] = side})
  14.             elseif sType == "modem" then
  15.                 if peripheral.call(side,"isWireless") then
  16.                     print("WIFI not suported yet")
  17.                 else
  18.                     print("Expoloring Network "..side)
  19.                     local tDevices = peripheral.call(side,"getNamesRemote")
  20.                     local pings = 0
  21.                     print(tostring(#tDevices).." devices found.")
  22.                     for _,device in pairs(tDevices) do
  23.                         local sType = peripheral.call(side,"getTypeRemote",device)
  24.                         if sType == "monitor" then
  25.                             table.insert(tScreen,{["type"] = "wire",["modemSide"] = side,["deviceID"] = device})
  26.                             pings = pings + 1
  27.                         end
  28.                     end
  29.                     print("found "..tostring(pings).." monitors out of "..tostring(#tDevices).." devices")
  30.                 end
  31.             end
  32.         else
  33.             print(side.." No peripheral Present")
  34.         end
  35.     end
  36.     return tScreen
  37. end
  38.  
  39. local function connect(tMonitor)
  40.  
  41.     local termX,termY = term.getSize()
  42.     local tFunctions = {"write","scroll","setCursorPos","setCursorBlink","getCursorPos",
  43.     "getSize","clear","clearLine","setTextColour","setTextColor", -- setTextScale
  44.     "setBackgroundColour","setBackgroundColor","isColour","isColor",}
  45.     local tPassed = {}
  46.     tPassed.direct = {}
  47.     tPassed.wire = {}
  48.     -- evluate candidats
  49.     for _,device in pairs(tMonitor) do
  50.         for size = 1.5,0.5,-0.5 do
  51.             local monX,monY
  52.             if device.type == "direct" then
  53.                 peripheral.call(device.side,"setTextScale",size)
  54.                 monX,monY = peripheral.call(device.side,"getSize")
  55.             elseif device.type == "wire" then
  56.                 peripheral.call(device.modemSide,"callRemote",device.deviceID,"setTextScale",size)
  57.                 monX,monY = peripheral.call(device.modemSide,"callRemote",device.deviceID,"getSize")
  58.             end
  59.             if monX >= termX and monY >= termY then
  60.                 table.insert(tPassed[device.type],device)
  61.                 break
  62.             end
  63.         end
  64.     end
  65.    
  66.     local tOut = {}
  67.    
  68.     print("Running pack process")
  69.    
  70.     for _,item in pairs(tFunctions) do
  71.         local tempFunction =  function()
  72.             return function(...)
  73.                 for k,v in pairs(tPassed.direct) do
  74.                     peripheral.call(v.side,item,...)
  75.                 end
  76.                 for k,v in pairs(tPassed.wire) do
  77.                     peripheral.call(v.modemSide,"callRemote",v.deviceID,item,...)
  78.                 end
  79.                 return term.native[item](...)
  80.             end
  81.         end
  82.         tOut[item] = tempFunction()
  83.     end
  84.    
  85.     return tOut
  86.    
  87. end
  88.  
  89. local tArg = {...}
  90.  
  91. if tArg[1] then
  92.     term.redirect()
  93. else
  94.     local newTerm = connect(grabScreens())
  95.     term.redirect(newTerm)
  96.     term.clear()
  97.     term.setCursorPos(1,1)
  98.     term.write("test")
  99.     os.pullEvent()
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement