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

js-shell-emulator

v1.0.7

Published

JS Shell Emulator is a dead simple JavaScript library for emulating a terminal environment

Downloads

8

Readme

JS Shell Emulator

JS Shell Emulator is a dead simple pure JavaScript library for emulating a shell environment.

DEMO

This package is inspired from eosterberg/terminaljs but written with async/await functions and features enriched.

Install

# Using NPM
npm install js-shell-emulator`

# Using Yarn
yarn add js-shell-emulator

Get started

Create a container element with an id.


<div id="container"></div>

Import module and create a JsShell instance.

import { JsShell } from "js-shell-emulator";

let shell = new JsShell("#container")
shell.print(`Hello, world!`)

Methods

Display text & content

// prints a text line
shell.print("Print this message")

// prints a rich html text
shell.printHTML("<strong>Print this bold message</strong>")

// prints a piece of text without line break at the end
shell.write("Print this")

// progressive display, simulates typing. Prints a char every 50ms 
shell.type("This will be displayed gradually", 50)

// prints a piece of text without line break at the end
shell.write("Print this ")
  .write("message")
  .newLine()

Prompt for input


// Ask for text
let name = await shell.input("What's your name?")

// Ask for a secret, input won't be shown during typing.
let secret = await shell.password("Enter your password")

// Ask for confirmation. "(y/n)" will be append at the end of the question. 
let confirm = await shell.confirm("Are you sure?")

Interface customization

Constructor options

Below are the (default) styling options that you can pass in the constructor second parameter.

const shell = new JsShell('#container', {
  backgroundColor: '#000',
  textColor: '#fff',
  className: 'jsShell', // this class will be applied on the shell root element.
  cursorType: 'large', // Typing cursor style: "large" ▯ or "thin" |
  cursorSpeed: 500, // blinking interval in ms
  fontFamily: 'Ubuntu Mono, Monaco, Courier, monospace',
  forceFocus: false, // whether or not inputs should capture document focus even if active element is outside the shell
  textSize: '1em',
  promptPS: '', // Prompt PS1 prefix ($, #, > or whatever you like) 
  width: '100%', // Shell root element css width
  height: '300px', // Shell root element css height
  margin: '0',
  overflow: 'auto',
  whiteSpace: 'break-spaces',
  padding: '10px',
})

Dynamic setters

You can programatically update styles using the follow setters:

 shell
  .setTextSize('0.9rem')
  .setTextColor('green')
  .setFontFamily('consolas')
  .setForceFocus(true)
  .setBackgroundColor('#000')
  .setWidth('100%')
  .setHeight('400px')
  .setMargin('10px auto')
  .setBlinking(true) // start or stop cursor blinking
  .setPrompt('$ ')
  .setVisible(true)  // show or hide terminal

Custom CSS

The package is CSS free, but you can apply any other styles on the root terminal class:

.jsShell {
    opacity: 0.9;
    line-height: 120%;
}

Play time

// Wait a second
await JsShell.sleep(1000)

// Give user a break
await shell.pause("Press any key to continue.")

Other methods

// Clear the terminal screen
shell.clear()

// Focus the shell prompt
shell.focus()

License

See LICENSE.md