Advertisement
RamiLego

CCMonitor++

May 16th, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. --Monitor++ By RamiLego4Game--
  2. --Boot--
  3. term.setTextColor(colors.white)
  4. term.setBackgroundColor(colors.black)
  5. term.clear()
  6. term.setCursorPos(1,1)
  7.  
  8. local tArgs = { ... }
  9. if #tArgs < 3 and (not tArgs[2]=="true" or not tArgs[2]=="false") then
  10.   term.setTextColor(colors.red)
  11.   print("Usage: monitor++ <side> <touch> <program> <arguments>")
  12.   return
  13. end
  14.  
  15. local sName = tArgs[1]
  16. if peripheral.getType( sName ) ~= "monitor" then
  17.     print( "No monitor named ".. sName )
  18.     return
  19. end
  20.  
  21. local sProgram = tArgs[3]
  22. local sPath = shell.resolveProgram( sProgram )
  23. if sPath == nil then
  24.     print( "No such program: "..sProgram )
  25.     return
  26. end
  27.  
  28. local monitor = peripheral.wrap(tostring(tArgs[1]))
  29.  
  30. local oldterm = term.current()
  31. local nterm = {}
  32. --Functions--
  33. function nterm.write(text)
  34.   oldterm.write(text)
  35.   monitor.write(text)
  36.   return(text)
  37. end
  38.  
  39. function nterm.clear()
  40.   oldterm.clear()
  41.   monitor.clear()
  42. end
  43.  
  44. function nterm.clearLine()
  45.   oldterm.clearLine()
  46.   monitor.clearLine()
  47. end
  48.  
  49. function nterm.getCursorPos()
  50.   return oldterm.getCursorPos()
  51. end
  52.  
  53. function nterm.setCursorPos(x,y)
  54.   oldterm.setCursorPos(x,y)
  55.   monitor.setCursorPos(x,y)
  56. end
  57.  
  58. function nterm.setCursorBlink(bool)
  59.   oldterm.setCursorBlink(bool)
  60.   monitor.setCursorBlink(bool)
  61. end
  62.  
  63. function nterm.isColor()
  64.   if not oldterm.isColor() or not monitor.isColor() then
  65.     return false
  66.   else
  67.     return true
  68.   end
  69. end
  70.  
  71. nterm.isColour = nterm.isColor
  72.  
  73. function nterm.getSize()
  74.   return oldterm.getSize()
  75. end
  76.  
  77. function nterm.setTextColor(num)
  78.   oldterm.setTextColor(num)
  79.   monitor.setTextColor(num)
  80. end
  81.  
  82. nterm.setTextColour = nterm.setTextColor
  83.  
  84. function nterm.setBackgroundColor(num)
  85.   oldterm.setBackgroundColor(num)
  86.   monitor.setBackgroundColor(num)
  87. end
  88.  
  89. nterm.setBackgroundColour = nterm.setBackgroundColor
  90.  
  91. function nterm.setTextScale(num)
  92.     monitor.setTextScale(num)
  93. end
  94.  
  95. --launcher--
  96. term.redirect(nterm)
  97.  
  98. local co = coroutine.create( function()
  99.     shell.run( sProgram, unpack( tArgs, 4 ) )
  100. end )
  101.  
  102. local function resume( ... )
  103.     local ok, param = coroutine.resume( co, ... )
  104.     if not ok then
  105.         printError( param )
  106.     end
  107.     return param
  108. end
  109.  
  110. local ok, param = pcall( function()
  111.     local sFilter = resume()
  112.     while coroutine.status( co ) ~= "dead" do
  113.         local tEvent = { os.pullEventRaw() }
  114.         if sFilter == nil or tEvent[1] == sFilter or tEvent[1] == "terminate" then
  115.             sFilter = resume( unpack( tEvent ) )
  116.         end
  117.         if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "mouse_click") and tArgs[2]=="true" then
  118.             if tEvent[1] == "monitor_touch" and tEvent[2] == sName then
  119.                 sFilter = resume( "mouse_click", 1, unpack( tEvent, 3 ) )
  120.             end
  121.         end
  122.         if coroutine.status( co ) ~= "dead" and (sFilter == nil or sFilter == "term_resize") then
  123.             if tEvent[1] == "monitor_resize" and tEvent[2] == sName then
  124.                 sFilter = resume( "term_resize" )
  125.             end
  126.         end
  127.     end
  128. end )
  129.  
  130. term.redirect(term.native())
  131.  
  132. if not ok then
  133.     printError( param )
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement