Scripts2026年7月27日·1 分钟阅读

Clack — Beautiful CLI Prompts for Node.js

A set of prompt components for building interactive command-line interfaces with a polished look. Includes text inputs, select menus, confirmations, spinners, and multi-step flows with minimal API surface.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Single
信任
信任等级:Established
入口
Clack
安全暂存命令
npx -y tokrepo@latest install 2bfa972f-897b-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

Clack is a library for building beautiful, interactive command-line prompts in Node.js. Created by Nate Moore (co-creator of Astro), it provides a set of composable prompt components with a polished terminal UI out of the box. Clack focuses on developer experience: prompts look professional, the API is minimal, and multi-step flows feel cohesive. Tools like the Astro CLI, SvelteKit, and Drizzle ORM use Clack for their interactive setup wizards.

What Clack Does

  • Provides styled prompt components: text, password, select, multiselect, confirm, and group
  • Renders spinners, progress indicators, and log messages with consistent styling
  • Chains prompts into multi-step wizards with intro/outro framing
  • Handles cancellation gracefully with SIGINT detection and cleanup
  • Offers a core layer for building custom prompt components with full rendering control

Architecture Overview

Clack is split into two packages: @clack/prompts (high-level components) and @clack/core (low-level primitives). The core package manages terminal state, cursor movement, input handling, and ANSI rendering. Prompt components are state machines that transition between idle, active, and submitted states. The rendering engine uses a double-buffered approach to minimize flicker, redrawing only changed lines on each keystroke.

Self-Hosting & Configuration

  • Install via npm: npm install @clack/prompts
  • Import prompt functions individually for tree-shaking
  • No configuration files needed; styling is built into the components
  • Works in Node.js 16+ and Bun
  • Use @clack/core to build custom prompt components with full terminal control

Key Features

  • Consistent visual design across all prompt types with Unicode box-drawing characters
  • Group prompts into logical sections with group() for multi-step wizards
  • Spinner component for long-running operations with start/stop/update methods
  • Cancellation handling with isCancel() check after each prompt
  • Minimal API surface: each prompt is a single async function call

Comparison with Similar Tools

  • Inquirer.js — The established choice with many prompt types and plugins; Clack offers a more modern look and smaller API
  • Enquirer — Feature-rich with custom prompt types; Clack prioritizes visual consistency and simplicity
  • Prompts — Lightweight alternative; Clack adds polished styling and multi-step flow support
  • Commander.js — Argument parser, not a prompt library; Commander handles flags while Clack handles interactive input
  • Ink — React-based terminal UI framework; Clack is simpler for standard prompt flows without React overhead

FAQ

Q: Can I customize the look of Clack prompts? A: The high-level @clack/prompts package has a fixed visual style. For custom rendering, use @clack/core to build prompt components with your own ANSI styling.

Q: Does Clack work with TypeScript? A: Yes. Clack is written in TypeScript and all prompt functions have full type definitions, including generic types for select options.

Q: How does Clack handle user cancellation (Ctrl+C)? A: Each prompt returns a special cancel symbol when the user presses Ctrl+C. Use the isCancel() helper to detect this and exit gracefully.

Q: Which projects use Clack? A: Astro CLI, SvelteKit, Drizzle ORM, and several other developer tools use Clack for their interactive setup and configuration wizards.

Sources

讨论

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

相关资产