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

cli-explorer

v0.0.1

Published

State-driven explorer for command line interfaces

Downloads

5

Readme

cli-explorer

State-driven explorer for command line interfaces.

Features:

  • makes nearly no assumptions about your interface (only basic input ESC/RETURN/BACKSPACE/ARROWS, but can be disabled)
  • easily pluggable

Install

npm install --save cli-explorer

Usage

cliExplorer = require("cli-explorer")

// cliExplorer(options:Object)
cliExplorer({
  onSelect: (state, ceInst) => {
    if (state.selection.length === 0) { // initial
      state.options = {
        true: "Yes",
        false: "No"
      }
      state.type = "inlineList"
      state.print = {question: "Is everything alright?"}
    } else {
      state.selection // ["true"] or ["false"] depending on the selection
    }
  },
}).then(async (ceInst) =>
  // started
  
  // to wait for stop
  ceInst.done.then(({selection, cursor}) => {
    // stopped
  })

  // to stop
  {selection, cursor} = await ceInst.stop()
  
  // restart
  await ceInst.start(selection: selection, cursor: cursor)
)

Options

Name | type | default | description ---:| --- | ---| --- onSelect | Function | - | (required) cb for building the explorer selection | Array | - | Selection for initialization cursor | String | - | Cursor for initialization stdin | Stream | process.stdin | Stream to listen for input stdout | Stream | process.stdout | Stream for output onInput | Function(key, ceInst) | - | Global input cb onPrint | Function(printState, ceInst) | - | Global print cb disabled | Array | [] | Globally disabled actions plugins | Array | - | Plugins to load, absolute Path or js functions allowed

state

In onSelect you get access to state which you can manipulate to change the output.

cliExplorer({
  onSelect: (state, ceInst) => {
    state.type // the plugin to select, see below under Plugins
    // available options
    // set to false if there are none
    state.options 
    state.print // printState, see below
    state.onInput // onInput cb only for current selection
    state.onPrint // onPrint cb only for current selection
    state.actions // Array of additional actions
    state.disabled // Array of disabled actions
  }
})

printState

Always available options. Plugins may have additional options.

cliExplorer({
  onSelect: (state, ceInst) => {
    state.print = {
      lines: ["first line"], // set array of printed lines
      question: "Question?", // print a question above options
      // append additional usage
      addUsage: "someAction[z]",
      // to merge with default keymap:
      keys:
        exit: ["q"] // will result in exit[esc/q]
    }
  }
})

Plugins

list

cliExplorer({
  onSelect: (state, ceInst) => {
    state.type = "list"
    state.options = {
      first: "First",
      second: "Second"
    }
    state.print = {
      prefix: [" ",">"]
    }
  }
})

inlineList

cliExplorer({
  onSelect: (state, ceInst) => {
    state.type = "inlineList"
    state.options = {
      first: "First",
      second: "Second"
    }
    state.print = {
      prefix: [" ",">"],
      postfix: [" ",">"]
      maxLength: 80 // line length
    }
  }
})

Write your own Plugins

Have a look at the source of the list / inlineList plugin, it is very easy.

License

Copyright (c) 2018 Paul Pflugradt Licensed under the MIT license.