Advertisement
theoriginalbit

CCPresenter (Master)

Mar 23rd, 2013
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. --[[
  2. CCPresenter by TheOriginalBIT
  3. Version 1.0
  4. First Created: 22 March 2013
  5. Last Updated: 23 March 2013
  6.  
  7. Inspired by, and continuation of: http://www.computercraft.info/forums2/index.php?/topic/11003-remote-presentation/
  8. ]]
  9.  
  10. local args = {...}
  11.  
  12. local function stop(msg)
  13.   _G.ccpresenter_loaded = false
  14.   term.restore()
  15.   print('Stopping service...')
  16.   rednet.broadcast('service_closed')
  17.   sleep(1)
  18. end
  19.  
  20. if #args == 1 and args[1] == '-stop' then -- restore the term so nothing more is sent
  21.   stop()
  22.   return
  23. elseif #args == 1 and args[1] == '-reset' then -- developer use only, reloads the program
  24.   stop()
  25. elseif #args > 0 then -- if an arg has been supplied and its not valid or there are too many args
  26.   printError('invalid runtime argument(s) supplied')
  27.   return
  28. end
  29.  
  30. -- if this program has been run before, exit, it doesn't need to be run all the time since
  31. if _G.ccpresenter_loaded then
  32.   print('Service already started...')
  33.   sleep(1)
  34.   term.clear()
  35.   term.setCursorPos(1,1)
  36.   return
  37. end
  38.  
  39. -- error without line numbers and stuff
  40. _G.nonVerboseError = function(msg) printError(msg) error() end
  41. _G.findPeripheral = function( t ) for _,s in pairs(rs.getSides()) do if peripheral.getType(s) == t then return s end end nonVerboseError('No '..t..' attached to the computer') end
  42. _G.sendPacket = function(method, ...) rednet.broadcast(textutils.serialize({ _m = method, _a = {...} })) end
  43.  
  44. -- make a term object and redirect to it
  45. termObj = setmetatable({}, {__index = term.native})
  46.  
  47. termObj.scroll = function(n)
  48.   term.native.scroll(n)
  49.   sendPacket('scroll', n)
  50. end
  51.  
  52. termObj.setCursorPos = function(x,y)
  53.   term.native.setCursorPos(x,y)
  54.   sendPacket('setCursorPos', x, y)
  55. end
  56.  
  57. termObj.write = function( ... )
  58.   term.native.write( ... )
  59.   sendPacket('write', ...)
  60. end
  61.  
  62. termObj.clear = function()
  63.   term.native.clear()
  64.   sendPacket('clear')
  65. end
  66.  
  67. termObj.clearLine = function()
  68.   term.native.clearLine()
  69.   sendPacket('clearLine')
  70. end
  71.  
  72. -- only add the colour functions when they are in the term api, this allows support for pre-cc1.4
  73. if term.setTextColor then
  74.   termObj.setTextColor = function(c)
  75.     term.native.setTextColor(c)
  76.     sendPacket('setTextColor', c)
  77.   end
  78.  
  79.   termObj.setTextColour = termObj.setTextColor
  80. end
  81.  
  82. -- only add the colour functions when they are in the term api, this allows support for pre-cc1.4
  83. if term.setBackgroundColor then
  84.   termObj.setBackgroundColor = function(c)
  85.     term.native.setBackgroundColor(c)
  86.     sendPacket('setBackgroundColor', c)
  87.   end
  88.  
  89.   termObj.setBackgroundColour = termObj.setBackgroundColor
  90. end
  91.  
  92. termObj.setCursorBlink = function(b)
  93.   term.native.setCursorBlink(b)
  94.   sendPacket('setCursorBlink', b)
  95. end
  96.  
  97. _G.ccpresenter_loaded = true
  98.  
  99. print('Starting up service...')
  100. sleep(1)
  101.  
  102. term.redirect( termObj )
  103. rednet.open( findPeripheral( 'modem' ) )
  104.  
  105. term.clear()
  106. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement