npm install shuxstreaming shell multiplexer

like screen or tmux but as pure javascript library instead of a program
server.js:
`` js
var net = require('net');
var shux = require('shux')();
shux.createShell('xyz');
var server = net.createServer(function (stream) {
var sh = shux.attach('xyz');
stream.pipe(sh).pipe(stream);
});
server.listen(5000);
`
You can connect to this server directly with netcat or telnet but it will have
annoying local echo and won't have a way to detach without externally killing
the process. Here's a client script you can use that detaches on ctrl-a d
(like gnu screen) and sets raw mode to turn off local echo:
client.js:
` js
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();
});
`
` js`
var shux = require('shux')
Create a new shell multiplexer shx.
Create a shell with the name id or opts.id.
Return a duplex stream sh that can be hooked into the local stdin and stdoutshx.attach(id)
to obtain a shell session. When the session ends, the shell will still be alive
and can be re-attached with .
Optionally, you can set:
* opts.command - the command to use for the shell, default: 'bash'opts.command
* opts.arguments - extra arguments to pass to the , default: []
* opts.columns - width of the session in characters
* opts.rows - height of the session in characters
Connect to the session at id if it exists, returning a duplex stream sh.undefined
Otherwise return .
Optionally, you can set:
* opts.columns - width of the session in characters
* opts.rows - height of the session in characters
Send a kill signal to the shell process at id, if it exists.
Return a list of the active shell id strings.
When a subshell gets spawned, the 'spawn' event fires for that shell id.
When a subshell exits, the 'exit' event fires for that shell id.
When a subshell is attached, the 'attach' event fires for that shell id.
When a subshell is detached, the 'detach' event fires for that shell id.
With npm do:
```
npm install shux
MIT