@cli-prompts/multiline

中文文档
1.0.0发布于 2025/11/16MITTypeScriptESM + CJS近 30 天下载 2797

A production-ready multiline text prompt for Node.js CLIs. Flicker-free, smooth, and supports full cursor movement with rich ANSI rendering. Built to fill the gap the other great libraries never covered.

原始使用文档
文档目录7 节
  1. ✨ Features
  2. 📦 Installation
  3. 🚀 Usage
  4. ⚙️ API & Options
  5. 🎨 Styling
  6. ⌨️ Key Bindings
  7. 📄 License

@cli-prompts/multiline

npm version License: MIT

A modern, flicker-free, feature-rich multiline text input for your command-line applications.

Have you ever been frustrated that inquirer and other great libraries are missing a proper, smooth multiline text input? This package solves that. It's a standalone component designed from the ground up to provide a first-class "textarea" experience in the terminal.

Multiline Demo GIF

✨ Features

  • True Multiline Editing: A native-like textarea experience in the terminal.
  • Intuitive Key-bindings: Enter to submit, Shift+Enter for newlines.
  • Advanced Editing: Word-wise navigation (Ctrl+Left/Right) and deletion (Alt+Backspace, Ctrl+W).
  • Robust Paste Support: Reliably paste multi-line text without accidentally submitting.
  • Rich Feature Set: Supports placeholders, default values, validation, and max length.
  • Animated Spinners: Optional loading spinner for a dynamic feel.
  • Deeply Customizable: Change prefixes, colors, and more with a simple style object.
  • Flicker-Free: Built with a smart, atomic render loop.
  • Lightweight & Modern: Zero runtime dependencies, written in TypeScript.
  • Battle-Tested: High unit test coverage.

📦 Installation

# pnpm
pnpm add @cli-prompts/multiline

# npm
npm install @cli-prompts/multiline

# yarn
yarn add @cli-prompts/multiline

# bun
bun add @cli-prompts/multiline

🚀 Usage

import { multiline, AbortError } from '@cli-prompts/multiline';

async function main() {
  try {
    const description = await multiline({
      prompt: 'Please enter your project description:',
      placeholder: 'My project is about...\nIt does really cool things!',
    });

    console.log('\nYour description:\n ', description);
  } catch (error) {
    if (error instanceof AbortError) {
      // The user aborted the prompt (Ctrl+C).
      // The component already printed a cancellation message.
    } else {
      console.error('An unexpected error occurred:', error);
    }
  }
}

main();

⚙️ API & Options

The multiline function accepts a string for a simple prompt, or an options object for full configuration.

multiline(options: MultilineOptions): Promise<string>

OptionTypeDefaultDescription
promptstringRequiredThe main question to ask the user.
defaultstring''A default value to pre-populate the input with. Supports \n for newlines.
placeholderstringundefinedPlaceholder text to show when the input is empty. Supports \n for newlines.
instructionstring | booleantrueA help message shown below the input. Set to false to hide, or a string to override.
requiredbooleanfalseIf true, prevents submission if the input is empty or only whitespace.
validate(value: string) => boolean | stringundefinedA function to validate the input on submission. Return true if valid, or a string for an error message.
maxLengthnumberundefinedThe maximum number of characters allowed. Provides real-time feedback.
spinnerbooleanfalseIf true, replaces the ? prefix with an animated spinner.
styleobject{...}An object to customize prefixes and colors. See "Styling" section below.

🎨 Styling

You can customize the look and feel by passing a style object. You only need to provide the properties you want to override.

Example:

import chalk from 'chalk';

multiline({
  prompt: 'Enter commit message',
  style: {
    prefixes: {
      prompt: '🤔',
      success: '✅',
    },
    colors: {
      prompt: 'yellow', // Use a predefined color name
      finalAnswer: str => chalk.italic.hex('#888')(str), // Or use a custom function
    },
  },
});

Style Object Structure:

{
  prefixes?: {
    prompt?: string;    // default: '?'
    success?: string;   // default: '✔'
    error?: string;     // default: '✖'
    input?: string;     // default: '›'
  };
  colors?: {
    prompt?: ColorFn | ColorName;      // default: 'cyan'
    success?: ColorFn | ColorName;     // default: 'green'
    error?: ColorFn | ColorName;       // default: 'red'
    instruction?: ColorFn | ColorName; // default: 'gray'
    placeholder?: ColorFn | ColorName; // default: 'gray'
    finalAnswer?: ColorFn | ColorName; // default: 'cyan'
    inputPrefix?: ColorFn | ColorName; // default: 'gray'
    promptTitle?: ColorFn | ColorName; // default: 'bold'
  };
}

ColorName can be one of: 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray'. ColorFn is a function (str: string) => string.

⌨️ Key Bindings

KeyAction
EnterSubmit the input
Shift + Enter / Alt + EnterInsert a new line
Ctrl + CAbort the prompt
BackspaceDelete character left
DeleteDelete character right
Alt + BackspaceDelete word left
Ctrl + WDelete word left
Arrow KeysMove cursor
Ctrl + LeftMove to previous word
Ctrl + RightMove to next word

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

版本与发布记录

@cli-prompts/multiline 共发布 1 个版本,首次发布于 2025/11/16;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.0.0latest2025/11/1611 个月前

关于 @cli-prompts/multiline 的常见问题

@cli-prompts/multiline 是什么?

A production-ready multiline text prompt for Node.js CLIs. Flicker-free, smooth, and supports full cursor movement with rich ANSI rendering. Built to fill the gap the other great libraries never covered.

如何安装 @cli-prompts/multiline?

在项目目录运行 npm install @cli-prompts/multiline,或使用 pnpm add / yarn add / bun add。

@cli-prompts/multiline 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cli-prompts/multiline 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cli-prompts/multiline 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cli-prompts/multiline 可以商用吗?

@cli-prompts/multiline 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cli-prompts/multiline 的下载量有多少?

根据 npm 官方下载统计,@cli-prompts/multiline 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,797 次,日均约 93 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cli-prompts/multiline 还在维护吗?

最新版本 1.0.0 发布于 2025/11/16(11 个月前);至今共发布 1 个版本,其中过去 12 个月发布了 1 个;首次发布于 2025/11/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。