@cli-promts/多线
用于命令行应用程序的现代、无闪烁、内容丰富的多行文本输入.
你曾经感到沮丧吗 inquirer 其它伟大的库缺少适当的,平滑的多行文本输入 ? 这个包解决了这个问题。 由地上而上设计的独立组件,提供终端的一等"文本区"体验.

* 特性
- 真多行编辑 : 在终端里有类似本地文字区的体验.
- 直观密钥绑定:
Enter提交,Shift+Enter为新行. - 高级编辑 : 文字导航( W)
Ctrl+Left/Right)和删除(Alt+Backspace, (中文(简体) ),Ctrl+W) (中文(简体) ). - 强力粘贴支持 : 可靠地粘贴多行文本而不意外提交 .
- 丰富的特性集 : 支持占位符、默认值、验证和最大长度.
- 动画自旋器 : 动态感觉的可选加载自旋器 .
- 深度自定义 : 更改前缀,颜色,以及更简单的样式对象.
- 自由飞翔: 由智能原子制成的回路所建.
- 轻量级( M) : 零运行时间依赖性,用 TypeScript 写出.
- 战斗测试: 高单位测试覆盖率.
* 安装
# pnpm
pnpm add @cli-prompts/multiline
# npm
npm install @cli-prompts/multiline
# yarn
yarn add @cli-prompts/multiline
# bun
bun add @cli-prompts/multiline
使用量
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 选项
这个 multiline 函数接受简单提示的字符串,或完全配置的选项对象.
multiline(options: MultilineOptions): Promise<string>
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
prompt | string | 需求 | 问取取用者所取之正问. |
default | string | '' | 预添加输入的默认值 。 支助 \n 为新行. |
placeholder | string | undefined | 当输入为空时要显示的占位符文本 。 支助 \n 为新行. |
instruction | string | boolean | true | 输入下面显示的帮助信息 。 设定为 false 要隐藏,或者要覆盖字符串. |
required | boolean | false | 若为 true,防止在输入为空或仅为空白时提交. |
validate | (value: string) => boolean | string | undefined | 用于验证提交时输入的函数。 返回时 true 如果有效,或错误消息的字符串. |
maxLength | number | undefined | 允许的最大字符数 。 提供实时反馈. |
spinner | boolean | false | 若为 true,替换 ? 前缀有动画自旋器. |
style | object | {...} | 用于自定义前缀和颜色的对象 。 见下"造型"一节. |
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}史蒂林 {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢
你可以自定义的外观和感觉 通过一个 style 对象。 您只需要提供您想要覆盖的属性 .
示例
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
},
},
});
样式对象结构 :
{
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 可以是: 'black', (中文(简体) ), 'red', (中文(简体) ), 'green', (中文(简体) ), 'yellow', (中文(简体) ), 'blue', (中文(简体) ), 'magenta', (中文(简体) ), 'cyan', (中文(简体) ), 'white', (中文(简体) ), 'gray'。 。 。 . ColorFn 是函数 (str: string) => string。 。 。 .
QQ 密钥绑定
| 密钥 | 行动 |
|---|---|
Enter | 提交输入 |
Shift + 键 Enter 编号 : Alt + 键 Enter | 插入新行 |
Ctrl + 键 C | 中止提示 |
Backspace | 删除左边的字符 |
Delete | 删除字符右边 |
Alt + 键 Backspace | 删除左字 |
Ctrl + 键 W | 删除左字 |
Arrow Keys | 移动光标 |
Ctrl + 键 Left | 移动到上一个单词 |
Ctrl + 键 Right | 移动到下一个单词 |
许可证
这个项目根据麻省理工学院许可证颁发——见 自由主义 详细文件.