diff --git a/apps/mirror.lua b/apps/mirror.lua index 5066cff..c763d57 100644 --- a/apps/mirror.lua +++ b/apps/mirror.lua @@ -1,84 +1,25 @@ require = requireInjector(getfenv(1)) -local Socket = require('socket') local Terminal = require('terminal') -local Logger = require('logger') local process = require('process') -Logger.setScreenLogging() - -local remoteId local args = { ... } -if #args == 1 then - remoteId = tonumber(args[1]) -else - print('Enter host ID') - remoteId = tonumber(read()) +local mon = device[table.remove(args, 1) or 'monitor'] +if not mon then + error('mirror: Invalid device') end -if not remoteId then - error('Syntax: telnet ') +mon.clear() +mon.setTextScale(.5) +mon.setCursorPos(1, 1) + +local oterm = Terminal.copy(term.current()) +Terminal.mirror(term.current(), mon) + +term.current().getSize = function() return mon.getSize() end + +if #args > 0 then + shell.run(unpack(args)) + Terminal.copy(oterm, term.current()) + + mon.setCursorBlink(false) end - -print('connecting...') -local socket - -for i = 1,3 do - socket = Socket.connect(remoteId, 5901) - if socket then - break - end - os.sleep(3) -end - -if not socket then - error('Unable to connect to ' .. remoteId .. ' on port 5901') -end - -print('connected') - -local function wrapTerm(socket) - local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write', - 'setTextColor', 'setTextColour', 'setBackgroundColor', - 'setBackgroundColour', 'scroll', 'setCursorBlink', } - - socket.term = multishell.term - socket.oldTerm = Util.shallowCopy(socket.term) - - for _,k in pairs(methods) do - socket.term[k] = function(...) - if not socket.queue then - socket.queue = { } - os.queueEvent('mirror_flush') - end - table.insert(socket.queue, { - f = k, - args = { ... }, - }) - socket.oldTerm[k](...) - end - end -end - -wrapTerm(socket) - -os.queueEvent('term_resize') - -while true do - local e = process:pullEvent('mirror_flush') - if e == 'terminate' then - break - end - if not socket.connected then - break - end - if socket.queue then - socket:write(socket.queue) - socket.queue = nil - end -end - -for k,v in pairs(socket.oldTerm) do - socket.term[k] = v -end - -socket:close() diff --git a/apps/mirrorClient.lua b/apps/mirrorClient.lua new file mode 100644 index 0000000..9e8aa43 --- /dev/null +++ b/apps/mirrorClient.lua @@ -0,0 +1,84 @@ +require = requireInjector(getfenv(1)) +local Socket = require('socket') +local Terminal = require('terminal') +local Logger = require('logger') +local process = require('process') + +Logger.setScreenLogging() + +local remoteId +local args = { ... } +if #args == 1 then + remoteId = tonumber(args[1]) +else + print('Enter host ID') + remoteId = tonumber(read()) +end + +if not remoteId then + error('Syntax: mirrorClient ') +end + +print('connecting...') +local socket + +for i = 1,3 do + socket = Socket.connect(remoteId, 5901) + if socket then + break + end + os.sleep(3) +end + +if not socket then + error('Unable to connect to ' .. remoteId .. ' on port 5901') +end + +print('connected') + +local function wrapTerm(socket) + local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write', + 'setTextColor', 'setTextColour', 'setBackgroundColor', + 'setBackgroundColour', 'scroll', 'setCursorBlink', } + + socket.term = multishell.term + socket.oldTerm = Util.shallowCopy(socket.term) + + for _,k in pairs(methods) do + socket.term[k] = function(...) + if not socket.queue then + socket.queue = { } + os.queueEvent('mirror_flush') + end + table.insert(socket.queue, { + f = k, + args = { ... }, + }) + socket.oldTerm[k](...) + end + end +end + +wrapTerm(socket) + +os.queueEvent('term_resize') + +while true do + local e = process:pullEvent('mirror_flush') + if e == 'terminate' then + break + end + if not socket.connected then + break + end + if socket.queue then + socket:write(socket.queue) + socket.queue = nil + end +end + +for k,v in pairs(socket.oldTerm) do + socket.term[k] = v +end + +socket:close() diff --git a/sys/apis/socket.lua b/sys/apis/socket.lua index 51fb36a..a7e8bae 100644 --- a/sys/apis/socket.lua +++ b/sys/apis/socket.lua @@ -1,7 +1,7 @@ local Logger = require('logger') local socketClass = { } -local trustList +local trustList = Util.readTable('.known_hosts') function socketClass:read(timeout) @@ -218,6 +218,4 @@ function Socket.server(port, keepAlive) end end -trustList = Util.readTable('.known_hosts') - return Socket diff --git a/sys/apis/terminal.lua b/sys/apis/terminal.lua index b391110..ab6bae5 100644 --- a/sys/apis/terminal.lua +++ b/sys/apis/terminal.lua @@ -84,9 +84,7 @@ function Terminal.toGrayscale(ct) for _,v in pairs(methods) do local fn = ct[v] ct[v] = function(c) - if scolors[c] then - fn(scolors[c]) - end + fn(scolors[c]) end end @@ -107,9 +105,7 @@ function Terminal.toGrayscale(ct) local function translate(s) if s then - for k,v in pairs(bcolors) do - s = s:gsub(k, v) - end + s = s:gsub("%d+", bcolors) end return s end @@ -132,14 +128,14 @@ function Terminal.getNullTerm(ct) return nt end -function Terminal.copy(ot) - local ct = { } - for k,v in pairs(ot) do +function Terminal.copy(it, ot) + ot = ot or { } + for k,v in pairs(it) do if type(v) == 'function' then - ct[k] = v + ot[k] = v end end - return ct + return ot end function Terminal.mirror(ct, dt) diff --git a/sys/network/snmp.lua b/sys/network/snmp.lua index c31087f..43b083c 100644 --- a/sys/network/snmp.lua +++ b/sys/network/snmp.lua @@ -130,6 +130,7 @@ local function sendInfo() info.point = turtle.point info.inventory = turtle.getInventory() info.coordSystem = turtle.getState().coordSystem + info.slotIndex = turtle.getSelectedSlot() end device.wireless_modem.transmit(999, os.getComputerID(), info) end