0.2.0 • Published 8 years ago

cli-input v0.2.0

Weekly downloads
199
License
MIT
Repository
github
Last release
8 years ago

Table of Contents

Prompt

Prompt and user input library, a component of the toolkit.

Install

npm i cli-input --save

Features

  • ANSI escape sequences fully supported.
  • Comprehensive history file support.
  • Tab completion functions.
  • Schema validation.
  • Native type coercion.
  • Infinite REPL prompts.
  • Collate multiple prompts (set) into an object.
  • Collections of common prompt sets (username/password etc).
  • Question prompts (arbitrary input).
  • Confirmation prompts (binary response).
  • Silent prompts (passwords etc).
  • Select option lists.
  • Multiline input.

Documentation

See the examples, test specifications have a poke around the source and see below.

Usage

var prompt = require('cli-input');
var ps = prompt({infinite: true});
ps.on('value', function(value, options, ps) {
  // do something with value
})
ps.run();

Options

The Prompt class accepts the following options at instantiation:

  • input: Input stream, default is process.stdin.
  • output: Output stream, default is process.stdout.
  • prompt: Default prompt string, defaults to >.
  • replace: Replacement character for silent prompts, default is *.
  • infinite: Whether the prompt should be displayed infinitely, default is false.
  • native: Object that defines configuration for native type coercion, default is null.
  • restore: When running in infinite mode and another set of prompts is executed, should the default infinite prompt be displayed at the end of the run, default is true.
  • repeat: Repeat prompt on invalid input, default is true.
  • trim: Remove leading and trailing whitespace from input lines, default is false.
  • split: Split line into an array on the specified string or regexp, default is null.
  • delimiter: Default value for the :delimiter format property, default is .
  • name: Default value for the :name format property, default is path.basename(process.argv[1]).
  • format: Prompt format string specification, default is :name :delimiter :location :status :message :default.

Prompt

prompt(options, cb)

Show a single prompt.

run(prompts, cb)

Run an array of prompt definitions and invoke callback with the result. The result contains a map property which maps the definitions key to the input value.

select(options, cb)

Display select menu output followed by a prompt.

multiline(options, cb)

Capture multiline input.

Note this overrides several internal readline module methods, use with discretion.

Examples

Examples are in the example directory, execute an example with:

node example/repl.js

Caution: the above example executes commands via the shell, be careful.

Developer

Test

Run all tests with code coverage:

npm test

Execute an individual test with:

npm run pretest && NODE_ENV=test ./node_modules/.bin/mocha --reporter list ./test/spec/confirm.js

Readme

To build the readme file from the partial definitions (requires mdp):

npm run readme

Generated by mdp(1).

0.2.0

8 years ago

0.1.13

8 years ago

0.1.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

10 years ago

0.0.92

10 years ago

0.0.91

10 years ago

0.0.90

10 years ago

0.0.89

10 years ago

0.0.88

10 years ago

0.0.87

10 years ago

0.0.86

10 years ago

0.0.85

10 years ago

0.0.83

10 years ago

0.0.82

10 years ago

0.0.75

10 years ago

0.0.74

10 years ago

0.0.73

10 years ago

0.0.72

10 years ago

0.0.71

10 years ago

0.0.62

10 years ago

0.0.58

10 years ago

0.0.53

10 years ago

0.0.52

10 years ago

0.0.49

10 years ago

0.0.48

10 years ago

0.0.40

10 years ago

0.0.38

10 years ago

0.0.36

10 years ago

0.0.26

10 years ago

0.0.23

10 years ago

0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.15

10 years ago

0.0.13

10 years ago

0.0.7

10 years ago

0.0.1

10 years ago