搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案