npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shux

v1.0.0

Published

streaming shell multiplexer

Downloads

181

Readme

shux

streaming shell multiplexer

build status

like screen or tmux but as pure javascript library instead of a program

example

re-attachable single-session tcp shell server

server.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:

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();
});

methods

var shux = require('shux')

var shx = shux()

Create a new shell multiplexer shx.

var sh = shx.createShell(id, opts)

Create a shell with the name id or opts.id.

Return a duplex stream sh that can be hooked into the local stdin and stdout to obtain a shell session. When the session ends, the shell will still be alive and can be re-attached with shx.attach(id).

Optionally, you can set:

  • opts.command - the command to use for the shell, default: 'bash'
  • opts.arguments - extra arguments to pass to the opts.command, default: []
  • opts.columns - width of the session in characters
  • opts.rows - height of the session in characters

var sh = shx.attach(id, opts)

Connect to the session at id if it exists, returning a duplex stream sh. Otherwise return undefined.

Optionally, you can set:

  • opts.columns - width of the session in characters
  • opts.rows - height of the session in characters

shx.destroy(id, sig)

Send a kill signal to the shell process at id, if it exists.

shx.list()

Return a list of the active shell id strings.

events

shx.on('spawn', function (id) {})

When a subshell gets spawned, the 'spawn' event fires for that shell id.

shx.on('exit', function (id) {})

When a subshell exits, the 'exit' event fires for that shell id.

shx.on('attach', function (id) {})

When a subshell is attached, the 'attach' event fires for that shell id.

shx.on('detach', function (id) {})

When a subshell is detached, the 'detach' event fires for that shell id.

install

With npm do:

npm install shux

license

MIT