Configs2026年7月4日·1 分钟阅读

Enquirer — Stylish Interactive Prompts for Node.js

A fast, lightweight library for creating elegant interactive CLI prompts. Supports input, confirm, list, autocomplete, and many more prompt types with a plugin architecture.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Prompt
安装
Single
信任
信任等级:Established
入口
Enquirer Overview
先审查命令
npx -y tokrepo@latest install 74075db7-773f-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

Introduction

Enquirer is a Node.js library for building interactive command-line prompts. It ships with a collection of built-in prompt types and a plugin system for creating custom ones. The library emphasizes speed, small footprint, and an intuitive API for CLI tool authors.

What Enquirer Does

  • Provides 15+ built-in prompt types including input, confirm, select, multiselect, and autocomplete
  • Supports prompt composition — chain multiple prompts or nest them inside each other
  • Renders prompts with ANSI styling, spinners, and real-time validation feedback
  • Offers a plugin architecture for registering custom prompt types
  • Handles keypresses, cursor movement, and terminal resize events gracefully

Architecture Overview

Enquirer uses a base Prompt class that manages the prompt lifecycle: initialize, render, keypress handling, submit, and cancel. Each built-in prompt type extends this class with specific rendering and validation logic. The rendering engine writes directly to the terminal using ANSI escape codes, avoiding heavy dependencies on large TUI frameworks. State changes trigger re-renders, keeping the display in sync with user input.

Self-Hosting & Configuration

  • Install via npm; no native dependencies or build steps required
  • Import individual prompt types for smaller bundles: const { Select } = require('enquirer')
  • Customize appearance with theme options for colors, symbols, and separator styles
  • Set default values, initial input, and validation functions per prompt
  • Works in any Node.js environment with TTY support

Key Features

  • 15+ prompt types out of the box (input, number, confirm, select, multiselect, scale, sort, snippet, etc.)
  • Real-time input validation with customizable error messages
  • Autocomplete and fuzzy-matching for large option lists
  • Composable prompt chains with conditional branching
  • Small footprint with no heavy dependencies

Comparison with Similar Tools

  • Inquirer.js — the most popular prompt library; larger dependency tree and slower rendering than Enquirer
  • prompts — minimal and lightweight; fewer built-in prompt types and less customization
  • @clack/prompts — modern prompt library with beautiful defaults; newer with a smaller ecosystem
  • readline (Node.js built-in) — low-level; requires manual input handling and rendering

FAQ

Q: How does Enquirer compare to Inquirer.js? A: Enquirer is faster, has fewer dependencies, and offers a more extensible plugin system. Inquirer has broader ecosystem adoption and more third-party plugins.

Q: Can I create custom prompt types? A: Yes. Extend the base Prompt class and register your custom type with enquirer.register('myType', MyPrompt).

Q: Does Enquirer support async validation? A: Yes. Pass an async function as the validate option; the prompt waits for resolution before accepting or rejecting input.

Q: Can I use Enquirer in CI/non-interactive environments? A: Enquirer requires a TTY. In CI, provide answers programmatically via the initial/default options or skip prompts.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产