1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-05 08:26:16 +00:00
opus/sys/apps/mirrorClient.lua

87 lines
1.7 KiB
Lua
Raw Normal View History

requireInjector(getfenv(1))
local Event = require('event')
local Logger = require('logger')
local Socket = require('socket')
2017-04-09 00:06:31 +00:00
local Terminal = require('terminal')
local Util = require('util')
2017-04-09 00:06:31 +00:00
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 <host ID>')
end
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 = { }
2017-07-24 02:37:07 +00:00
Event.onTimeout(0, function()
if socket.queue then
socket:write(socket.queue)
socket.queue = nil
end
end)
2017-04-09 00:06:31 +00:00
end
table.insert(socket.queue, {
f = k,
args = { ... },
})
socket.oldTerm[k](...)
end
end
end
while true do
2017-05-10 10:11:25 +00:00
print('connecting...')
local socket
while true do
socket = Socket.connect(remoteId, 5901)
if socket then
break
end
os.sleep(3)
2017-04-09 00:06:31 +00:00
end
2017-05-10 10:11:25 +00:00
print('connected')
wrapTerm(socket)
os.queueEvent('term_resize')
while true do
2017-07-24 02:37:07 +00:00
local e = Event.pullEvent()
2017-08-05 08:17:06 +00:00
if e[1] == 'terminate' then
2017-05-10 10:11:25 +00:00
break
end
if not socket.connected then
break
end
2017-04-09 00:06:31 +00:00
end
2017-05-10 10:11:25 +00:00
for k,v in pairs(socket.oldTerm) do
socket.term[k] = v
2017-04-09 00:06:31 +00:00
end
2017-05-10 10:11:25 +00:00
socket:close()
2017-04-09 00:06:31 +00:00
2017-05-10 10:11:25 +00:00
end