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 🙏

© 2026 – Pkg Stats / Ryan Hefner

terminal-api

v0.1.7

Published

terminal-api is a thin layer around low-level terminal commands, providing easy access without escape codes or other dirty details.

Readme

terminal-api

Installation | Usage | API | Colors | Styles | License

terminal-api is a thin layer around low-level terminal commands, providing easy access without escape codes or other dirty details.

  • Manages terminal states
  • Handles position, color and styling
  • Supports 256 color
  • No dependencies

Installation ^

npm install --save terminal-api

Usage ^

const TerminalApi = require('terminal-api');

// initialize
const t = new TerminalApi();

// clear screen
t.clear();

// show/hide cursor
t.setCursor(false);

// set background/foreground color
t.setBgColor(t.colors.basic.magenta);
t.setFgColor(t.colors.rgb6(4, 5, 1));

// set styles
t.setStyles({bold: true, underline: true});

// set position
t.setPosition(10, 5);

// write
t.write('Hello world!');

// shortcut methods
t.w('Goodbye world!', {
    x: 10, y: 7,
    bgColor: t.colors.basic.white,
    fgColor: t.colors.gray[3],
    styles: ['strikethrough', 'dim'],
    wrap: true
});

Also, run examples/demo.js to see a more colorful example:

node examples/demo.js

API ^

constructor(stream, encoding) ^

Creates terminal-api instance.

  • stream: WritableStream. Default: process.stdout
  • encoding: String. Default: 'utf8'

setStream(stream) ^

Sets stream.

  • stream: WritableStream. Default: process.stdout

setEncoding(encoding) ^

Sets encoding.

  • encoding: String. Default: 'utf8'

setOptions(options, force) ^

Sets multiple options at a time.

  • options: Object. Possible keys: wrap, x, y, bgColor, fgColor, cursor, styles
  • force: Boolean. Forces operation even if not needed. Default: false

setWrap(wrap) ^

Enables/disables wrapping at the end of the line.

  • wrap: Boolean. Default: true

setPosition(x, y, force) ^

Sets cursor position.

  • x: Number. Default: 0
  • y: Number. Default: 0
  • force: Boolean. Forces operation even if not needed. Default: false

setX(x, force) ^

Sets cursor x position.

  • x: Number. Default: 0
  • force: Boolean. Forces operation even if not needed. Default: false

setY(y, force) ^

Sets cursor y position.

  • y: Number. Default: 0
  • force: Boolean. Forces operation even if not needed. Default: false

setBgColor(color, force) ^

Sets background color. See Colors for more information.

  • color: Number.
  • force: Boolean. Forces operation even if not needed. Default: false

setFgColor(color, force) ^

Sets foreground color. See Colors for more information.

  • color: Number.
  • force: Boolean. Forces operation even if not needed. Default: false

resetBgColor(force) ^

Resets background color to terminal default.

  • force: Boolean. Forces operation even if not needed. Default: false

resetFgColor(force) ^

Resets foreground color to terminal default.

  • force: Boolean. Forces operation even if not needed. Default: false

setCursor(cursor, force) ^

Shows/hides cursor.

  • cursor: Boolean. Default: true
  • force: Boolean. Forces operation even if not needed. Default: false

setStyles(styles, force) ^

Enables/disables multiple styles at once. See Styles for more information.

  • styles: Object. Should be structured as {styleName: styleState}
  • force: Boolean. Forces operation even if not needed. Default: false

enableStyles(styleList, force) ^

Enables multiple styles at once. See Styles for more information.

  • styleList: Array. List of style names.
  • force: Boolean. Forces operation even if not needed. Default: false

disableStyles(styleList, force) ^

Disables multiple styles at once. See Styles for more information.

  • styleList: Array. List of style names.
  • force: Boolean. Forces operation even if not needed. Default: false

reset() ^

Resets terminal and instance state.

clear() ^

Clears terminal.

write(text) ^

Writes text on terminal.

  • text: String.

w(text, options, revert, force) ^

Shortcut method for changing options, writing text, and optionally reverting options back.

  • text: String.
  • options: Object. See setOptions method.
  • revert: Boolean. Whether to revert options back after writing. Default: false
  • force: Boolean. Forces operation even if not needed. Default: false

Colors ^

Color availability and representations might differ between systems and configurations. For maximum compatibility, only basic and bright colors should be used.

Even though there are 256 colors, it's not the usual 256 color space. On most systems, these color groups partially overlap with each other.

While terminal-api accepts only color codes, colors object provides access to color codes in a user-friendly way. It can be accessed from class or instance:

const TerminalApi = require('terminal-api');
const colors = TerminalApi.colors;
// or
const t = new TerminalApi();
const colors = t.colors;

colors object is structured as:

const colors = {
  basic: { /* black, red, green, yellow, blue, magenta, cyan, white */ },
  bright: { /* black, red, green, yellow, blue, magenta, cyan, white */ },
  gray: [/* 0, ..., 23 */]
};

Also, it has a minimal API.

Colors API ^

rgb6(r, g, b)

Returns color code for given rgb values of 256 colors.

  • r: Number. Must be in range 0 - 5. Default: 0
  • g: Number. Must be in range 0 - 5. Default: 0
  • b: Number. Must be in range 0 - 5. Default: 0
rgb256(r, g, b)

Returns closest color code for given rgb values of 16M colors.

  • r: Number. Must be in range 0 - 255. Default: 0
  • g: Number. Must be in range 0 - 255. Default: 0
  • b: Number. Must be in range 0 - 255. Default: 0
rgb256Hex(hex)

Returns closest color code for given rgb values of 16M colors.

  • hex: String. Must be hexadecimal RGB code. Default: 000000

Usage ^

const TerminalApi = require('terminal-api');
const t = new TerminalApi();
t.setBgColor(t.colors.basic.magenta);
t.setFgColor(t.colors.rgb256Hex('#ff9900'));

Styles ^

Available styles: 'bold', 'dim', 'italic', 'underline', 'blink', 'inverse', 'hidden', 'strikethrough'

Style availability depends on system. For maximum compatibility, only bold, underline and reverse should be used.

License ^

MIT