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 🙏

© 2025 – Pkg Stats / Ryan Hefner

xterm-js-shell

v1.1.3

Published

Building block for CLI environments for xterm.js

Readme

xterm-js-shell

Building block for CLI environments for xterm.js

<script src="//unpkg.com/xterm-js-shell/bundle.js"></script>

-- OR --

npm install --save xterm-js-shell

const XtermJSShell = require('xterm-js-shell/bundle.js')
const terminal = new Terminal()

const shell = new XtermJSShell(terminal)

shell
  .command('help', async (shell) => {
    await shell.printLine(`
Try running one of these commands:
${shell.commands.map((command) => ` - ${command}`).join('\n')}

`)
  })
  .command('curl', async (shell, [ url ]) => {
    const response = await fetch(url)

    const text = await response.text()

    await shell.print(text)
  })
  .command('echo', async (shell, args) => {
    let message = null

    if (args.length) await shell.printLine(args.join(' '))

    // Loop until they hit enter without typing anything
    while (message = await shell.readLine('')) {
      await shell.printLine(message)
    }
  })
  .command('confirm', async (shell) => {
    const char = await shell.readChar('Y/n?')

    await shell.printLine(char)
  })
  .command('ssh', async (shell, {url}) => {
    // For use with https://github.com/RangerMauve/websocket-shell-service

    if(!url) url = 'ws:localhost:8080'

    const socket = new WebSocket(url)

    let closed = false

    socket.onclose = () => {
      closed = true
      shell.printLine(`Connection to ${url} closed`)
    }

    socket.onmessage = ({data}) => {
      shell.print(data)
    }

    for await(let data of shell.readStream()) {
      if(closed) break
      socket.send(data)
    }
  })

// Start the Read-Eval-Print-Loop
shell.repl()

terminal.open(someElement)

Features:

  • Takes an xterm.js terminal instance
  • Keyboard navigation, history, tab completion using local-echo
  • Able to define commands with a name and an async function or an async generator
  • Commands take a shell instance, and args array
  • Commands should be able to readLine, readChar from the shell
  • Commands can yield data from the generator for output, or invoke print / printLine
  • Commands should be abele to read raw data from the terminal as a stream
  • After a command resolves or rejects, it's shell should throw whenever there's input
  • Commands should be able to "take over" the terminal to prevent default processing
    • Useful for stuff like SSH
    • Shell will take back control after the program exits
  • Able to detach shell from the terminal