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

iosplit

v1.1.1

Published

Separate input and output to keep your cli clean.

Downloads

17

Readme

IOSplit

Library to separate input and output in cli applications. IOSplit allows you to print text to your terminal without any interference with user input. It uses blessed under the hood.

iosplit

Features

  • Creates scrollable output log and input field.
  • Fallbacks to Node's Readline in case stdout is not a terminal.
  • Overrides builtin console methods to act as drop-in replacement.
  • Keeps track of input history. Access it using arrow keys.
  • Saves and loads history from a file.

Example

const IOSplit = require("iosplit");

// Create an IOSplit instance
const iosplit = new IOSplit({
  history: true,
});

// Capture user input and evaluate it
iosplit.on("line", line => {
  console.log("»", line);
  try {
    const result = eval(line);
    console.log("←", result);
  } catch(err) {
    console.error(err);
  }
});

// Close program on stdin end(Ctrl-D)
iosplit.on("end", () => process.exit());

// Display example logs on fixed intervals
setInterval(() => console.warn("Random async warning!"), 3000);
setInterval(() => console.error("Random async error!"), 5000);

// Start IOSplit
iosplit.start();
console.log("Enter any js expression in the box below.");

The example is included in the repository. Clone it and use the following commands to run it:

npm run build
npm run example

API

new IOSplit([config])

Creates new IOSplit instance with specified config. config argument is an object of containing any of the following options:

| Property | type | default | description | |:--------------------------|:---------------------|:------------|:------------------------------------------------------------------------| | noConsole | boolean | false | Do not override console methods. | | force | boolean or undefined | undefined | Forcefully disables or enables screen splitting(blessed). Use undefined to automatically determine based on whenever stdout is a terminal. | | history | boolean or string | false | Specify the name of history file. Use .history if true is provided. | | ignoreUncaughtException | boolean | false | Do not destroy blessed screen on uncaught exception. | | ignoreCtrlC | boolean | false | Do not send SIGINT on Ctrl-C. | | style.log | blessed style | false | Style for log Element. | | style.line | blessed style | false | Style for line Element. | | style.input | blessed style | false | Style for input Element. |

Check out Blessed documentation to find more information regarding styling.

iosplit.enabled

Indicates whenever IOSplit instance is currently started.

iosplit.gui

Indicates whenever IOSplit uses Blessed Screen to control terminal.

iosplit.start()

Starts IOSplit instance and takes control over terminal. Additionally loads history file and overrides console methods if applicable. If the stdout is not connected to terminal, initializes Readline instead.

iosplit.stop()

Stops IOSplit instance and releases control over terminal. Also restores console methods to their original state.

iosplit.log(...args)

iosplit.warn(...args)

iosplit.error(...args)

Analogous to console counterparts. Use them if config.noConsole is true.

iosplit.refresh()

Re-renders interface.

event 'line'

Fires on new user input. Provided string contains entered line.

event 'end'

Fires when one of the following occur:

  • Received Ctrl-D to signal end-of-transmission(EOT).
  • Readline fires 'close' event if using fallback.
  • iosplit.stop() is called

This event indicates that no more 'line' events will fire, until IOSplit instance is restarted.

Note: If IOSplit instance is using fallback, it will not be able to receive any more input once received EOT. Even after restart.

event 'log'

Fires when adding a new log. Provided string contains formatted log entry.

event 'start'

Fires at the end of iosplit.start();

event 'stop'

Fires at the end of iosplit.stop();