BigSHinyToys

splitter terminal redirection tool

Jan 28th, 2013
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. --[[
  2.         splitter mk2
  3.         by BigSHinyToys
  4. ]]--
  5. local tArgs = {...}
  6. local sSide = {}
  7. for i,v in pairs(rs.getSides()) do
  8.     sSide[v] = true
  9. end
  10. local monSide
  11. local monBig = false
  12. local termX,termY = term.getSize()
  13. local customTerm = {}
  14. local moniter
  15. local oldMon = {}
  16.  
  17. if #tArgs == 1 then
  18.     if sSide[tArgs[1]] then
  19.         monSide = string.lower(tArgs[1])
  20.         if peripheral.isPresent(monSide) and peripheral.getType(monSide) == "monitor" then
  21.             for size = 1.5,0.5,-0.5 do
  22.                 peripheral.call(monSide,"setTextScale",size)
  23.                 local monX,monY = peripheral.call(monSide,"getSize")
  24.                 if monX >= termX and monY >= termY then
  25.                     monBig = true
  26.                     break
  27.                 end
  28.             end
  29.         end
  30.     elseif string.lower(tArgs[1]) == "restore" then
  31.         term.restore()
  32.         return
  33.     end
  34. else
  35.     print("USAGE: <side> or \"restore\" ")
  36. end
  37.  
  38. local function wrap( _sFunction )
  39.     return function( ... )
  40.         peripheral.call(monSide,_sFunction,...)
  41.         return oldMon[_sFunction](...)
  42.     end
  43. end
  44.  
  45. if monBig then
  46.     moniter = peripheral.wrap(monSide)
  47.     for k,v in pairs(term.native) do
  48.         oldMon[k] = v
  49.     end
  50.     for k,v in pairs( term.native ) do
  51.         if type( k ) == "string" and type( v ) == "function" then
  52.             customTerm[k] = wrap(k)
  53.         end
  54.     end
  55.     term.redirect(customTerm)
  56.     term.clear()
  57.     term.setCursorPos(1,1)
  58.     print("Running on monitor")
  59. else
  60.     print("Monitor to small")
  61. end
Advertisement
Add Comment
Please, Sign In to add comment