An open API service indexing awesome lists of open source software.

https://github.com/enquirer/prompt-history

This repository has been archived, use the built-in history functionality in Enquirer instead.
https://github.com/enquirer/prompt-history

answers enquirer history persist prompt store tab

Last synced: 8 months ago
JSON representation

This repository has been archived, use the built-in history functionality in Enquirer instead.

Awesome Lists containing this project

README

          

# prompt-history [![NPM version](https://img.shields.io/npm/v/prompt-history.svg?style=flat)](https://www.npmjs.com/package/prompt-history) [![NPM monthly downloads](https://img.shields.io/npm/dm/prompt-history.svg?style=flat)](https://npmjs.org/package/prompt-history) [![NPM total downloads](https://img.shields.io/npm/dt/prompt-history.svg?style=flat)](https://npmjs.org/package/prompt-history)

> Tab through previous answer history.

**Persist answers**

![prompt-history tabbing example](https://raw.githubusercontent.com/enquirer/prompt-history/master/docs/example-store.gif)

**Tab through answer history**

![prompt-history tabbing example](https://raw.githubusercontent.com/enquirer/prompt-history/master/docs/example-tabbing.gif)

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install prompt-history
```

## Usage

History can only be used with "text" prompts. This will not work with checkbox, list, radio prompts, etc.

```js
var Prompt = require('prompt-base');
var history = require('prompt-history');

// pass the prompt instance to "history()"
var prompt = history(new Prompt({
name: 'number',
message: 'Favorite number?',
}));

prompt.run()
.then(function(answer) {
console.log({number: answer});
})
.catch(console.log)
```

**How it works**

* tab+shift to go through previous answers, starting with most recent
* tab+shift to go in reverse

## Options

### options.historyLimit

Limit the number of answers to persist in the history array.

**Type**: `number`

**Default**: `Infinity`

**Example**

```js
var prompt = history(new Prompt({
name: 'number',
message: 'Favorite number?',
historyLimit: 10
}));
```

### options.path

Required: Customize the filepath for the persisted history store.

**Type**: `string`

**Default**: `~/.data-store/prompt-history.json`

**Example**

```js
var path = require('path');
var prompt = history(new Prompt({
name: 'number',
message: 'Favorite number?',
path: path.join(__dirname, 'custom-store-path.json')
}));
```

### options.store

Pass a custom instance of [data-store](https://github.com/jonschlinkert/data-store) for persisting answers.

**Type**: `object`

**Default**: instance of data-store

**Example**

```js
var Store = require('data-store');
var store = new Store('custom-name');

var prompt = history(new Prompt({
name: 'number',
message: 'Favorite number?',
store: store
}));
```

See [data-store](https://github.com/jonschlinkert/data-store) for all available features and options.

## About

### Related projects

* [enquirer](https://www.npmjs.com/package/enquirer): Intuitive, plugin-based prompt system for node.js. | [homepage](http://enquirer.io "Intuitive, plugin-based prompt system for node.js.")
* [prompt-base](https://www.npmjs.com/package/prompt-base): Base prompt module used for creating custom prompts. | [homepage](https://github.com/enquirer/prompt-base "Base prompt module used for creating custom prompts.")
* [prompt-password](https://www.npmjs.com/package/prompt-password): Password prompt. Can be used as a standalone prompt, or as a plugin for [Enquirer](http://enquirer.io). | [homepage](https://github.com/enquirer/prompt-password "Password prompt. Can be used as a standalone prompt, or as a plugin for [Enquirer].")
* [prompt-text](https://www.npmjs.com/package/prompt-text): Basic text input prompt. This can be used standalone, but it's also included in [enquirer… [more](https://github.com/enquirer/prompt-text) | [homepage](https://github.com/enquirer/prompt-text "Basic text input prompt. This can be used standalone, but it's also included in [enquirer] by default.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Brian Woodward**

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](https://twitter.com/doowb)

### License

Copyright © 2017, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 04, 2017._