# prompt-skeleton

> A consistent behavior for CLI prompts.

Latest version **1.0.4** (published 2022-01-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install prompt-skeleton
pnpm add prompt-skeleton
yarn add prompt-skeleton
bun add prompt-skeleton
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-01-28 |
| First published | 2016-04-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 5 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Jannis R |
| Maintainers | derhuerst |
| Keywords | command, line, cli, prompt, skeleton, behavior, key bindings |

## Links

- npm: https://www.npmjs.com/package/prompt-skeleton
- Repository: https://github.com/derhuerst/prompt-skeleton
- Issues: https://github.com/derhuerst/prompt-skeleton/issues
- npm.io page: https://npm.io/package/prompt-skeleton

## Dependencies (5)

- [pass-stream](https://npm.io/package/pass-stream.md) ^1.0.0
- [window-size](https://npm.io/package/window-size.md) ^1.1.0
- [ansi-escapes](https://npm.io/package/ansi-escapes.md) ^3.1.0
- [ansi-diff-stream](https://npm.io/package/ansi-diff-stream.md) ^1.2.1
- [@derhuerst/cli-on-key](https://npm.io/package/@derhuerst/cli-on-key.md) ^0.1.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2022-01-28
- 1.0.3 — 2022-01-28
- 1.0.2 — 2018-04-14
- 1.0.1 — 2018-04-05
- 1.0.0 — 2018-03-31
- 0.4.0 — 2017-01-20
- 0.3.3 — 2016-11-29
- 0.3.2 — 2016-11-28
- 0.3.1 — 2016-11-28
- 0.3.0 — 2016-11-24
- 0.2.0 — 2016-11-21
- 0.1.3 — 2016-11-04
- 0.1.2 — 2016-10-22
- 0.1.1 — 2016-04-07
- 0.1.0 — 2016-04-07

## README

# prompt-skeleton

This project aims to bring a **consistent behavior to CLI apps**.

Use [`cli-prompter`](https://github.com/ahdinosaur/cli-prompter) if you want to have batteries included or if you want to chain prompts.

[![npm version](https://img.shields.io/npm/v/prompt-skeleton.svg)](https://www.npmjs.com/package/prompt-skeleton)
[![dependency status](https://img.shields.io/david/derhuerst/prompt-skeleton.svg)](https://david-dm.org/derhuerst/prompt-skeleton#info=dependencies)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/prompt-skeleton.svg)
[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)
[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)

Instead of letting prompts parse user input by themselves, *prompt-skeleton* provides a [standard set of actions like `submit`](#actions), which prompts can act on by exposing methods. The key bindings are [readline](https://de.wikipedia.org/wiki/GNU_readline)-inspired.


## Projects using `prompt-skeleton`

Prompts:

- [`sms-cli`](https://github.com/derhuerst/sms-cli)
- [`date-prompt`](https://github.com/derhuerst/date-prompt)
- [`mail-prompt`](https://github.com/derhuerst/mail-prompt)
- [`multiselect-prompt`](https://github.com/derhuerst/multiselect-prompt)
- [`number-prompt`](https://github.com/derhuerst/number-prompt)
- [`range-prompt`](https://github.com/derhuerst/range-prompt)
- [`select-prompt`](https://github.com/derhuerst/select-prompt)
- [`text-prompt`](https://github.com/derhuerst/text-prompt)
- [`tree-select-prompt`](https://github.com/derhuerst/tree-select-prompt)
- [`cli-autocomplete`](https://github.com/derhuerst/cli-autocomplete)
- [`switch-prompt`](https://github.com/derhuerst/switch-prompt)

Other command line interfaces:

- [`really-basic-chat-ui`](https://github.com/derhuerst/really-basic-chat-ui)
- [`command-irail`](https://github.com/iRail/command-irail)
- [`cli-2048`](https://github.com/derhuerst/cli-2048)
- [`cli-minesweeper`](https://github.com/derhuerst/cli-minesweeper)
- [`tiny-cli-editor`](https://github.com/derhuerst/tiny-cli-editor)


## Installing

```
npm install prompt-skeleton
```


## Usage

```js
wrap(prompt) // Promise
```

To render to screen, [`write`](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback) to `prompt.out`. Because `prompt.out` is a [`ansi-diff-stream`](https://www.npmjs.com/package/ansi-diff-stream#usage), you can also clear the screen manually be calling `prompt.out.clear()`.

### Actions

You can process any of these actions by exposing a method `prompt[action]`.

- `first`/`last` – move to the first/last letter/digit
- `left`/`right`
- `up`/`down`
- `next` - for tabbing
- `delete` – remove letter/digit left to the cursor
- `space`
- `submit` – success, close the prompt
- `abort` – failure, close the prompt
- `reset`

### Example

This renders a prompt that lets you pick a number.

```js
const wrap = require('prompt-skeleton')

const prompt = wrap({
	value: 0,
	up: function () {
		this.value++
		this.render()
	},
	down: function () {
		this.value--
		this.render()
	},
	render: function () {
		this.out.write(`The value is ${this.value}.`)
	}
})

prompt
.then((val) => {
	// prompt succeeded, do something with the value
})
.catch((val) => {
	// prompt aborted, do something with the value
})
```


## Contributing

If you **have a question**, **found a bug** or want to **propose a feature**, have a look at [the issues page](https://github.com/derhuerst/prompt-skeleton/issues).

---
_Source: https://npm.io/package/prompt-skeleton · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
