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

console-term

v1.0.3

Published

Terminal control extensions to Node's default console class

Downloads

5

Readme

Console Terminal Extensions

Alternate terminal object to replace Node's default console. Adds colors, styles, cursor control, and clearing support.

To Install

npm i --save console-term

Usage

If you only want to use it like the global console, it works the same way so it's a drop-in replacement.

const terminal = require('console-term');
terminal.log('Hello, world!');

You can also create instances of it tied to streams (it defaults to process.stdout and process.stderr), like this:

const { ConsoleTerminal } = require('console-term'),
  fs = require('fs'),
  terminal = new ConsoleTerminal(fs.createWriteStream('out.log'), fs.createWriteStream('err.log'));

Keep in mind that any operation that prints an escape sequence will continue to do so regardless of what stream is attached. You can chain functions together like this:

const terminal = require('console-term');
terminal.clear()
  .setColor('red')
  .setStyle('bold')
  .log('This is a message in red printed using console.log!')
  .log('This is another log message chained to it!')
  .resetStyle();

Functions

All the standard Console functions are available as well as the ones documented below.

Clearing

  • clear(): Clears the entire screen and puts the cursor at 0,0
  • clearLine(): Clears the current line and puts the cursor at the first column
  • clearUp(): Clears lines above the current line
  • clearDown(): Clears lines below the current line
  • clearRight(): Clears the current line right of the cursor
  • clearLeft(): Clears the current line left of the cursor

Styling

  • resetStyle(): Resets the current formatting, colors, etc.
  • setColor(color): Sets the current foreground color, see Colors below
  • setBackgroundColor(color): Sets the current background color
  • setStyle(style): Sets the current display style, see Styles

Cursor

  • setCursorPos(x, y): Sets the current cursor position from top-left
  • moveCursor(c, direction): Moves the cursor the specified spaces in the specified direction, see Directions
  • moveCursorUp(c): Moves the cursor up the specified number of lines
  • moveCursorDown(c): Moves the cursor down the specified number of lines
  • moveCursorLeft(c): Moves the cursor left the specified number of columns
  • moveCursorRight(c): Moves the cursor right the specified number of columns

Printing

  • print(str): Prints a string (no added newline)
  • printHuge(str): Prints a string double height (newline added)
  • printWide(str): Prints a string double width

Meta

  • sendEscape(str): Prints the \033 escape sequence followed by the specified string
  • setEnableEscapes(allow): Sets whether to allow escape sequences to be printed (disabling this disables everything but print)
  • enableEscapes(): Same as setEnableEscapes(true)
  • disableEscapes(): Same as setEnableEscapes(false)

Reference

Below are reference lists for colors, styles, etc.

Colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray (or grey, only supported for foreground colors)

Styles

  • bold
  • dim
  • italic
  • underline
  • inverted
  • invisible
  • strikethrough

Directions

  • up
  • down
  • left
  • right