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

wslpty

v0.2.2

Published

Spawn native pseudoterminals for the Windows Subsystem for Linux

Downloads

14

Readme

wslpty

Spawn native pseudoterminals for the Windows Subsystem for Linux.

Notable features:

  • Full support for standard and custom escape sequences
  • Get name of current foreground terminal process
  • Customizable shell, working directory, environment and more

Usage

Install wslpty by running:

npm install wslpty

The following example sets up a terminal piped through stdout, then closes it after 5 seconds:

import * as wslpty from 'wslpty';

var ptyProcess = wslpty.spawn({
    cols: 80,
    rows: 30,
    cwd: '~'
});

ptyProcess.on('data', function (data) {
    process.stdout.write(data);
});

ptyProcess.write('ls -a\r');
ptyProcess.resize(40, 40);
ptyProcess.write('ls -a\r');

setTimeout(() => {
    ptyProcess.kill();
}, 5000);

Organization

Wslpty is built in two parts that communicate to each other over a TCP socket:

Frontend

A client written in Node.js that exposes the user-facing API and spawns the backend portion of the code. It spawns a TCP server on a randomly chosen port and starts the backend process. It is located in the frontend/ folder and runs on Windows at runtime.

Backend

A TCP client written in Rust that forks the pty and provides a translation layer between the socket communication and the pty. It is located in the backend/ folder and runs in WSL at runtime.

The backend is written in Rust because Rust can interop cleanly into C (where the forkpty capabilities live) and it compiles to a standalone binary. This is important because the backend runs within WSL itself. Even if a user is running Node.js from Windows (a must when using this package), they do not necessarily have Node.js installed within WSL. Providing a standalone binary avoids this problem.

Development

It is highly recommended that you develop wslpty within WSL itself. To develop, you will need the following:

  • Windows installation with WSL enabled
  • Node.js - 8.x or above
  • Rust - stable toolchain

Motivation

There are some wonderful tools out there that make working with pseudoterminals on Windows possible outside of the standard console host. They heavily inspired the design and implementation of this package, but come with some limitations:

  • winpty - makes it possible to create a pty in windows using an embedded conhost
    • Unable to track process names in the terminal
    • Conhost swallows or transforms some escape sequences, making TrueColor and some terminal integrations difficult or impossible
  • wslbridge - creates a pty in WSL and passes data out on a TCP socket to avoid the limitations of winpty
    • Designed for use specifically in Cygwin - not Node.js compatible
    • Associated wsltty terminal application lacks some features (such as tabs) that many people desire in terminals
  • node-pty - creates a pty in Linux/MacOS/Windows in Node.js
    • Uses winpty to create terminals in Windows, with all of its limitations
    • Starting from 0.8.0, the new ConPTY Windows interface is supported, but it only works for newer versions of Windows and still does not expose process name properly

This package combines the Node.js interface of node-pty (and some of its backend pseudoterminal code) with the socket-based communication pattern of wslbridge to make creation of a fully functional WSL pty effortless in Node.js.