搜索插件、代码仓与 APP 分类

插件详情v0.2.3

cli_repl

一个用于创建命令行界面 REPL 的简单库

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8.1万
喜欢数
5
Pub 分数
130

安装插件

flutter pub add cli_repl

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个轻量级的 Flutter/Dart 库,旨在简化命令行界面(CLI)读取-求值-打印循环(REPL)的创建。它使开发者能够以最少的设置构建交互式命令行工具,支持输入解析、命令执行和输出渲染。非常适合用于脚本工具、调试工具或需要通过终端命令进行用户交互的教育应用。该包跨平台,可在 Android、iOS、Web、macOS、Windows 和 Linux 上无缝运行。

适合场景

  • 构建交互式 CLI 工具
  • 创建调试控制台
  • 开发教育编程环境
  • 原型化命令行脚本
  • 实现自定义 REPL 接口

主要特点

  • 用于定义命令的简单 API
  • 跨平台兼容性
  • 内置的输入/输出处理
  • 支持异步命令执行
  • 可扩展的命令注册系统

适合对象

  • 开发 CLI 工具的开发者
  • 教育工作者正在构建互动式编码教程
  • 需要终端交互的工具创建者
  • 需要控制台功能的Flutter应用

使用建议

  • 需要理解命令行交互模式
  • 限制为文本输入/输出
  • 未针对高性能批处理进行优化
  • 可能需要为复杂的命令逻辑添加额外的错误处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

cli_repl

A simple library for creating CLI REPLs in Dart.

Features

Example Usage:

/// Echoes all entered lines
for (var line in new Repl().run()) {
  print(line);
} 
Statement Validation

By passing a validator to the Repl constructor, you can tell the REPL whether some entered text is a complete statement or not. The REPL calls this whenever a newline is entered to determine whether to yield a complete statement or continue it on a new line. The default validator returns true for all text.

Custom Prompts

By default, the REPL gives no prompt to the user when asking for a statement. You can change this by passing a prompt to the Repl constructor. By default, statement continuations on a new line will start with whitespace equal to the length of the prompt. You can override this by passing in continuation.

See example/example.dart for a demonstration of statement validation and custom prompts.

History

A history of entered lines is stored. History entries are modified when edited.

By default, a maximum of 50 entries are stored. You can change this by passing maxHistory into the Repl constructor.

Navigation
  • Left/Ctrl-B: Move left one character
  • Right/Ctrl-F: Move right one character
  • Home/Ctrl-A: Move to start of line
  • End/Ctrl-E: Move to end of line
  • Ctrl-L: Clear the screen
  • Ctrl-D: If there is text, delete the character under the cursor. If there is no text, exit.
  • Ctrl-F: Moves forward one character
  • Ctrl-B: Moves backward one character
  • Ctrl-U: Kill (cut) to start of line
  • Ctrl-K: Kill (cut) to end of line
  • Ctrl-Y: Yank (paste) previously killed text, inserting at cursor
  • Up/Down: Navigate within history
Testing REPLs

If running without a terminal, the input will be printed along with the prompts, allowing you to test REPLs made with this library by comparing stdout to the expected log input and output together.

See test/repl_test.dart for an example of this.

Running on Node

If you compile this to JS with Dart 2, you can run it on Node.

There are a couple of behavior differences:

  • Node's built-in readline library is used, so the supported navigation and history commands may vary from the Dart version.
  • Likewise, line history is managed by Node, and you can't change the maximum number of entries or edit history manually from Dart.
  • Only Repl.runAsync() works. Calling Repl.run() will throw an error.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目