goliatone / poke-repl

Remote REPL client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Intercept raw input to parse commands

goliatone opened this issue · comments

We want to be able to parse commands sent by server on client. Currently we can't since the socket is piped to the output. We could use through like shux:

var net = require('net');
var through = require('through');

var state = { meta: false };
var keyboard = through(function (buf) {
    if (buf.length === 1 && buf[0] === 1) return state.meta = true;
    
    if (state.meta && buf[0] === 'd'.charCodeAt(0)) {
        process.exit();
    }
    else this.queue(buf);
    state.meta = false;
});

var c = net.connect(5000);
keyboard.pipe(c).pipe(process.stdout);

process.stdin.setRawMode(true);
process.stdin.pipe(keyboard);

process.on('exit', function () {
    process.stdin.setRawMode(false);
    console.log();
});

Another option is two have two types of clients, one working on headless mode and one in interactive mode. The current client is interactive, we should add the headless mode. This would take a different ACK message and setup to relay messages to broader context.