diff --git a/plugins/core/ui/src/components/builtin/ShellComponent.vue b/plugins/core/ui/src/components/builtin/ShellComponent.vue index c86996279..b20b7e938 100644 --- a/plugins/core/ui/src/components/builtin/ShellComponent.vue +++ b/plugins/core/ui/src/components/builtin/ShellComponent.vue @@ -37,16 +37,22 @@ export default { const rootLocation = `${window.location.protocol}//${window.location.host}`; this.socket = eio(rootLocation, options); + this.socket.send(JSON.stringify({ dim: { cols: term.cols, rows: term.rows } })); + this.socket.on("message", (data) => { - term.write(new Uint8Array(Buffer.from(data))); + term.write(new Uint8Array(Buffer.from(JSON.parse(data).data))); }); term.onData((data) => { - this.socket.send(data); + this.socket.send(JSON.stringify({ data })); + }); + + term.on('resize', dim => { + this.socket.send(JSON.stringify({ dim })); }); term.onBinary((data) => { - this.socket.send(data); + this.socket.send(JSON.stringify({ data })); }); }, destroyed() { diff --git a/server/src/runtime.ts b/server/src/runtime.ts index e4f003de6..fa96cb39d 100644 --- a/server/src/runtime.ts +++ b/server/src/runtime.ts @@ -119,8 +119,15 @@ export class ScryptedRuntime extends PluginHttp { const spawn = require('node-pty-prebuilt-multiarch').spawn as typeof ptySpawn; const cp = spawn(process.env.SHELL, [], { }); - cp.onData(data => connection.send(data)); - connection.on('message', message => cp.write(message.toString())); + cp.onData(data => connection.send(JSON.stringify({data}))); + connection.on('message', message => { + const parsed = JSON.parse(message.toString()); + if (parsed.data) { + cp.write(parsed.data); + } else if (parsed.dim) { + cp.resize(parsed.dim.cols, parsed.dim.rows); + } + }); connection.on('close', () => cp.kill()); } catch (e) {