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

node-term-ui

v0.0.5

Published

UI Toolkit for node.js console apps

Downloads

6

Readme

TermUI

TermUI is a library for Node.js that makes it easier to create rich console interfaces.

General Usage

Rendering

  • out(text) - prints text to the screen from the current cursor position
  • clear() - clears the screen
  • pos(x,y) - positions the cursor
  • home() - sends the cursor to the top left corner
  • end() - sends the cursor to the bottom right corner
  • fg(color) - sets the foreground color
  • bg(color) - sets the background color
  • hifg(color) - sets the foreground color for 256 color terminals
  • hibg(color) - sets the background color for 256 color terminals
  • enableMouse() - enables mouse event handling
  • disableMouse() - disables mouse event handling
  • eraseLine() - erases the entire line that the cursor is on
  • hideCursor() - hides the cursor
  • showCursor() - shows the cursor

The following will print "Hello, world!" at 10, 20 in the terminal in white text on a red background:

  TermUI.pos(10,20).fg(TermUI.C.w).bg(TermUI.C.w).out("Hello, world!")

As you can see, pretty much everything is chainable.

Handy Rendering Shortcuts

The C object contains definitions for common colors so that you don't have to remember the numeric values.

  • k: black
  • r: red
  • g: green
  • y: yellow
  • b: blue
  • m: magenta
  • c: cyan
  • w: white
  • x: the terminal's default color

The S object is similar: it contains the text style definitions -- normal, bold, underline, blink, and inverse.

The SYM object contains shortcuts for some handy UTF8 characters: star, check x, triUp, triDown, triLeft, triRight, fn, arrowUp, arrowDown, arrowLeft, and arrowRight.

Events

resize is fired when the user resizes their terminal. The listener receives an object with 'w' and 'h' properties set to the new width and height of the terminal.

keypress is fired when a key is pressed. This works just like the keypress event on process.stdin

mousedown, mouseup, drag, wheel are all the mouse events that are fired. The receiver is sent an object that contains which button was pressed, which direction the wheel scrolled, the x/y location, and whether or not shift was pressed.

Widgets

Button

Buttons are simply clickable rectangular areas that can have a label on them. Here's how to use one...

	TermUI = require 'TermUI'

	TermUI.enableMouse()

	button = new TermUI.Button
		bounds:
			x: 0
			y: 0
			w: 30
			h: 3
			label: 'I am a banana!'
			labelAnchor: 5

	button.on 'mousedown', ->
		button.bg = TermUI.C.y
		button.draw()

	button.on 'mouseup', ->
		button.bg = TermUI.C.b
		button.draw()

	button.draw()