goliatone / poke-repl

Remote REPL client and server
MIT License
0 stars 0 forks source link

Intercept raw input to parse commands #17

Open goliatone opened 6 years ago

goliatone commented 6 years ago

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();
});
goliatone commented 5 years ago

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.