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

neat-input

v1.11.1

Published

A diff friendly cli input module. Made for usage with neat-log and ansi-diff-stream

Downloads

1,209

Readme

neat-input

A diff friendly cli input module. Made for usage with neat-log and ansi-diff-stream

Build Status

npm install neat-input

Very useful if you want to accept interactive user input in an application that does interactive output (such as writing a progress bar) without messing it up

Usage

To illustrate what this module does, try running the below example

var input = require('neat-input')({style: style})
var diff = require('ansi-diff-stream')()

var names = []
var seconds = 0

diff.pipe(process.stdout)

input.on('enter', function (line) {
  names.push(line)
})

setInterval(function () {
  seconds++
  update()
}, 1000)

input.on('update', update)
update()

function style (start, cursor, end) {
  if (!cursor) cursor = ' '
  return start + '[' + cursor + ']' + end
}

function update () {
  diff.write(`
    Welcome to name input. It has been ${seconds} since you started.

    Please enter your name: ${input.line()}
    Cursor position is ${input.cursor}

    Previously entered names: ${names.join(', ')}
  `)
}

Notice that as you are inputing a new name the UI is updating and things look the way they are supposed to, even though the output is being updated both above and below the input line.

Try deleting characters using backspace or moving the cursor around with the arrow keys

API

var input = neatPrompt([options])

Create a prompter. Options include:

{
  showCursor: false, // set to true to *not* hide the normal cli cursor while running the program
  style: function (start, cursor, end) {} // set to style the line output (default is not style)
}

input.line()

Returns the currently inputted line (styled)

input.rawLine()

Returns the line unstyled always.

input.set(rawLine)

Set the internal rawLine to a given string and move the cursor to the end

input.cursor

The current position of the cursor

input.enter(rawLine)

Set the internal rawline and trigger an enter event.

input.on('update')

Emitted everytime the input state is updated.

input.on('enter', line)

Emitted when an enter is clicked. Also sets the rawLine to an empty string.

input.on('tab')

Emitted when tab is clicked

input.on('up')

Emitted when the up key is clicked

input.on('down')

Emitted when the down key is clicked

input.on('left')

Emitted when the left key is clicked

input.on('right')

Emitted when the right key is clicked

input.on('space')

Emitted when the space key is clicked

input.on('backspace')

Emitted when the backspace key is clicked

input.on('pageup')

Emitted when page up is clicked

input.on('pagedown')

Emitted when page down is clicked

input.on('ctrl-<key>')

Emitted when ctrl + some key is pressed. If you do not provide a handler for ctrl-c the process will be exited for you on ctrl-c.

input.on('alt-<key>')

Emitted when alt + some key is pressed.

input.on('shift-<key>')

Emitted when shift + some control key is pressed.

input.on('keypress', ch, key)

Forwarded from the keypress module whenever a key is pressed.

Shortcuts

When typing on the command line, neat-input supports the following shortcuts:

  • ctrl-a move the cursor to the beginning of the line
  • ctrl-e move the cursor to the end of the line
  • ctrl-b move the cursor one character to the left
  • ctrl-f move the cursor one character to the right
  • ctrl-k erase all characters to the right of the cursor
  • ctrl-u erase the whole line
  • ctrl-w erase one word to the left of the cursor
  • alt-backspace same as ctrl-w
  • alt-d erase one word to the right of the cursor
  • alt-b move the cursor one word to the left
  • alt-f move the cursor one word to the right

License

MIT