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

live-prompt

v1.1.0

Published

Simple console with history and redux data flow.

Downloads

8

Readme

live-prompt

Simple console with history and redux data flow.

Circle CI npm version npm downloads

Contents

Description

This is a Node console built in with redux architecture.

Install

live-prompt can be installed via npm.

npm install live-prompt

Features

  • It remembers your commands and you can navigate around them with the arrow keys.

Getting Started

import livePrompt from 'live-prompt';

const options = {...},
  prompt = livePrompt(options);

prompt.start();

prompt.log('Hey!!');

prompt.stop();

Usage

Options

Default options:

options = {
  stdin = process.stdin,
  stdout = process.stdout,
  middleware = undefined,
  prompt = 'live-prompt:$ ',
  bye = 'see you soon!',
  onCtrlC = undefined,
  encoding = 'utf8'
}
  • @param {Object} [options.stdin] Readable stream.
  • @param {Object} [options.stdout] Writable stream.
  • @param {Function} [options.middleware] Redux middleware function.
  • @param {String} [options.prompt] Prompt.
  • @param {Object} [options.bye] Final greeting.
  • @param {Function} [options.onCtrlC] Callback to be called when ctrl-c is pressed.
  • @param {String} [options.encoding] Stdin encoding.

Prompt Object

livePrompt() returns an object with the next methods.

{
  start () {},
  stop () {},
  log (txt) {}
}

Start: sets stdin raw mode true, sets the encoding and subscribes for 'keypress' events.

Stop: unsubscribes stdin from 'keypress' events.

Log: logs txt to the stdout without loosing your command.

Middleware function

This is a common redux middleware function:

middleware = store => next => action => {
  ...
  return next(action);
}

Actions:

Commit is dispatched when you hit return.

{type: 'commit', data: 'command...'}

Prev is dispatched when you hit up arrow key.

{type: 'prev'}

Next is dispatched when you hit down arrow key.

{type: 'next'}

Left is dispatched when you hit left arrow key.

{type: 'left'}

Right is dispatched when you hit right arrow key.

{type: 'right'}

Cancel is dispatched when you hit ESC key.

{type: 'cancel'}

Backspace is dispatched when you hit backspace key.

{type: 'backspace'}

Any other key will be dispatched as chunk.

{type: 'chunk', data: 'chunk...'}

Data Tree Structure

This is the data tree of the state.

{
  history: {
    commands: [...], // array of committed commands.
    index: 0, // current index of the commands array. 
  },
  present: {
    buffer: '...', // it is the current command you are editing/navigating.
    current: '...', // keeps your last input while you are navigating around the history.
    cursor: 0, // current cursor position in buffer.
  }
}

Attention: The value of index being equal to the count of commands means that we are editing the present command.

Example

This example will record every committed command to 'commands.txt' and will log the date every 1 minute.

import livePrompt from 'live-prompt';
import fs from 'fs';

const commands = fs.createWriteStream('./commands.txt'),
  middleware = store => next => action => {
    if (action.type === 'commit') {
      commands.write(action.data);
    }
    return next(action);
  },
  prompt = livePrompt({middleware});

prompt.start();

setInterval(() => {
  prompt.log('[date]: ' + new Date());
}, 60000);

History Navigation

  • Navigate through your commands with up and down arrow keys.
  • Cancel edit mode hitting ESC once.
  • Go back to the last command hitting ESC twice.

Thanks