Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SBoudrias/Inquirer.js
A collection of common interactive command line user interfaces.
https://github.com/SBoudrias/Inquirer.js
cli command-line javascript javascript-library node-js nodejs prompt typescript
Last synced: about 1 month ago
JSON representation
A collection of common interactive command line user interfaces.
- Host: GitHub
- URL: https://github.com/SBoudrias/Inquirer.js
- Owner: SBoudrias
- License: mit
- Created: 2013-05-17T01:41:36.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2024-04-24T20:37:51.000Z (about 2 months ago)
- Last Synced: 2024-04-25T09:54:13.529Z (about 2 months ago)
- Topics: cli, command-line, javascript, javascript-library, node-js, nodejs, prompt, typescript
- Language: JavaScript
- Homepage:
- Size: 1.12 GB
- Stars: 19,372
- Watchers: 151
- Forks: 1,261
- Open Issues: 190
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Lists
- awesome-list - Inquirer.js
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-stars - Inquirer.js
- awesome-web-dev-resources - inquirer
- awesome-bookmarks - **Inquirer.js**
- awesome-f2e-libs - **inquirer** - 交互式命令接口,比如 prompt。 (命令行 / redux 扩展)
- awesome-nodejs-cn - Inquirer.js - 交互式的命令行弹框. (目录 / 命令行工具)
- awesome - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - Inquirer.js
- awesome-tools - inquirer - 在命令行里发起问答 (命令行)
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js
- my-awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-development - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-nodejs - Inquirer.js - Collection of common interactive command line user interfaces. ![](https://img.shields.io/github/stars/SBoudrias/Inquirer.js.svg?style=social&label=Star) (Repository / Command-line Utilities)
- awesome-cli-frameworks - Inquirer.js
- awesome-nodejs-cn - Inquirer.js - **star:19361** 交互式命令行提示符 ![star > 2000][Awesome] (包 / 命令行实用工具)
- awesome-javascript - Inquirer.js - A collection of common interactive command line user interfaces. (CLI)
- awesome-stars - Inquirer.js
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - Inquirer.js
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - Inquirer.js
- awesome-nodejs-cn - Inquirer.js - 交互式的命令行提示工具 (包 / 命令行工具)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-github-star - Inquirer.js
- awesome-stars - Inquirer.js
- awesome-list - inquirer - Command line prompt library (Node Libraries)
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-node - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-node.js - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- fuck-awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - Inquirer.js
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-star-libs - SBoudrias / Inquirer.js
- awesome-nodejs-cn - Inquirer.js - 交互式的命令行提示工具 (包 / 命令行工具)
- awesome-fe-resources - Inquirer.js
- awesome-andy-node - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-stars - Inquirer.js
- awesome-stars - Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome - Inquirer.js - A collection of common interactive command line user interfaces. (Command-line & Terminal Utilities / React Components)
- awesome-nodejs - Inquirer.js - 通用可交互命令行工具集合。 ![](https://img.shields.io/github/stars/SBoudrias/Inquirer.js.svg?style=social&label=Star) (GIT 仓库 / 命令行工具)
- awesome-things - Inquirer - A collection of common interactive command line user interfaces. (CLI apps development / Shell)
- awesome-nodejs-precise - Inquirer.js - square)]() | Interactive command-line prompt. | (Packages / Command-line utilities)
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-js - SBoudrias/Inquirer.js: A collection of common interactive command line user interfaces
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-stars - Inquirer.js
- jimsghstars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-sauce - Inquirer.js
- awesome-nodejs - Inquirer.js - A collection of common interactive command line user interfaces. - ★ 8564 (Command-line utilities)
- awesome-fe - **inquirer** - 交互式命令接口,比如 prompt。 (命令行 / macros)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (cli)
- awesome-nodejs-new - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome - inquirer - 交互式命令接口,比如 prompt。 (命令行)
- awesome-stars - Inquirer.js - node cli中与用户交互的工具 (NodeJS)
- awesome-nodejs - Inquirer.js - Interactive command-line prompt. (Packages / Command-line utilities)
- awesome-nodejs-modules - `Inquirer.js` - A collection of common interactive command line user interfaces. (Packages for development / Development)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript)
- awesome-cli - inquirer
- favorite-link - 常用交互式命令行用户界面的集合。
- awesome-tools - SBoudrias/Inquirer.js - Node.js 命令行交互工具,通用的命令行用户界面集合,可以和用户进行交互。 (Uncategorized / Uncategorized)
- awesome-stars - Inquirer.js - node cli中与用户交互的工具 (NodeJS)
- awesome-stars-webVueBlog - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (JavaScript / 运维\&DevOps)
- awesome-npm - inquirer - 命令行工具中的用户交互界面(包括「输入/选择/确认」等功能) (3. 命令行程序 / 3.1 开发库)
- awesome-web-cn - Inquirer.js - 一个用于 node.js 中命令行交互的库 (Uncategorized / Uncategorized)
- awesome-stars - SBoudrias/Inquirer.js - A collection of common interactive command line user interfaces. (typescript)
- awesome-nodejs-cn - Inquirer.js - Interactive command-line prompt. (包 / Command-line utilities)
README
# Inquirer
[![npm](https://badge.fury.io/js/@inquirer%2Fprompts.svg)](https://www.npmjs.com/package/@inquirer/prompts)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSBoudrias%2FInquirer.js.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FSBoudrias%2FInquirer.js?ref=badge_shield)A collection of common interactive command line user interfaces.
![List prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/list.svg)
Give it a try in your own terminal!
```sh
npx @inquirer/demo@latest
```# Installation
```sh
npm install @inquirer/promptsyarn add @inquirer/prompts
```Inquirer recently underwent a rewrite from the ground up to reduce the package size and improve performance. The previous version of the package is still maintained (though not actively developed), and offered hundreds of community contributed prompts that might not have been migrated to the latest API. If this is what you're looking for, the [previous package is over here](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/inquirer).
# Usage
```js
import { input } from '@inquirer/prompts';const answer = await input({ message: 'Enter your name' });
```# Prompts
## [Input](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/input)
![Input prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/input.svg)
```js
import { input } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/input) for usage example and options documentation.
## [Select](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/select)
![Select prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/list.svg)
```js
import { select } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/select) for usage example and options documentation.
## [Checkbox](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/checkbox)
![Checkbox prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/checkbox.svg)
```js
import { checkbox } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/checkbox) for usage example and options documentation.
## [Confirm](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/confirm)
![Confirm prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/confirm.svg)
```js
import { confirm } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/confirm) for usage example and options documentation.
## [Password](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/password)
![Password prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/password.svg)
```js
import { password } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/password) for usage example and options documentation.
## [Expand](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/expand)
![Expand prompt closed](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/expand-y.svg)
![Expand prompt expanded](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/expand-d.svg)```js
import { expand } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/expand) for usage example and options documentation.
## [Editor](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/editor)
Launches an instance of the users preferred editor on a temporary file. Once the user exits their editor, the content of the temporary file is read as the answer. The editor used is determined by reading the $VISUAL or $EDITOR environment variables. If neither of those are present, the OS default is used (notepad on Windows, vim on Mac or Linux.)
```js
import { editor } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/editor) for usage example and options documentation.
## [Raw List](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/rawlist)
![Raw list prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/rawlist.svg)
```js
import { rawlist } from '@inquirer/prompts';
```[See documentation](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/rawlist) for usage example and options documentation.
# Create your own prompts
The [API documentation is over here](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/core), and our [testing utilities here](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/testing).
# Advanced usage
All inquirer prompts are a function taking 2 arguments. The first argument is the prompt configuration (unique to each prompt). The second is providing contextual or runtime configuration.
The context options are:
| Property | Type | Required | Description |
| ----------------- | ----------------------- | -------- | ------------------------------------------------------------ |
| input | `NodeJS.ReadableStream` | no | The stdin stream (defaults to `process.stdin`) |
| output | `NodeJS.WritableStream` | no | The stdout stream (defaults to `process.stdout`) |
| clearPromptOnDone | `boolean` | no | If true, we'll clear the screen after the prompt is answered |Example:
```js
import { confirm } from '@inquirer/prompts';const allowEmail = await confirm(
{ message: 'Do you allow us to send you email?' },
{
output: new Stream.Writable({
write(chunk, _encoding, next) {
// Do something
next();
},
}),
clearPromptOnDone: true,
},
);
```## Canceling prompt
All prompt functions are returning a cancelable promise. This special promise type has a `cancel` method that'll cancel and cleanup the prompt.
On calling `cancel`, the answer promise will become rejected.
```js
import { confirm } from '@inquirer/prompts';const answer = confirm(...); // note: for this you cannot use `await`
answer.cancel();
```# Recipes
## Get answers in an object
When asking many questions, you might not want to keep one variable per answer everywhere. In which case, you can put the answer inside an object.
```js
import { input, confirm } from '@inquirer/prompts';const answers = {
firstName: await input({ message: "What's your first name?" }),
allowEmail: await confirm({ message: 'Do you allow us to send you email?' }),
};console.log(answers.firstName);
```## Ask a question conditionally
Maybe some questions depend on some other question's answer.
```js
import { input, confirm } from '@inquirer/prompts';const allowEmail = await confirm({ message: 'Do you allow us to send you email?' });
let email;
if (allowEmail) {
email = await input({ message: 'What is your email address' });
}
```## Get default value after timeout
```js
import { setTimeout } from 'node:timers/promises';
import { input } from '@inquirer/prompts';const answer = input(...);
const defaultValue = setTimeout(5000).then(() => {
answer.cancel();
return 'default answer';
});const answer = await Promise.race([defaultValue, answer])
```## Using as pre-commit/git hooks, or scripts
By default scripts ran from tools like `husky`/`lint-staged` might not run inside an interactive shell. In non-interactive shell, Inquirer cannot run, and users cannot send keypress events to the process.
For it to work, you must make sure you start a `tty` (or "interactive" input stream.)
If those scripts are set within your `package.json`, you can define the stream like so:
```json
"precommit": "my-script < /dev/tty"
```Or if in a shell script file, you'll do it like so: (on Windows that's likely your only option)
```sh
#!/bin/sh
exec < /dev/ttynode my-script.js
```# Community prompts
If you created a cool prompt, [send us a PR adding it](https://github.com/SBoudrias/Inquirer.js/edit/master/README.md) to the list below!
[**Interactive List Prompt**](https://github.com/pgibler/inquirer-interactive-list-prompt)
Select a choice either with arrow keys + Enter or by pressing a key associated with a choice.```
? Choose an option:
> Run command (D)
Quit (Q)
```# License
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))
Licensed under the MIT license.