zurbo

cc_splitter

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