パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.2.3

cli_repl

CLI REPL を作成するための簡単なライブラリ

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
8.1万
いいね数
5
Pub ポイント
130

パッケージをインストール

flutter pub add cli_repl

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

コマンドラインインターフェース(CLI)のリード・エヴァル・プリント・ループ(REPL)の作成を簡素化することを目的とした軽量なFlutter/Dartライブラリです。最小限のセットアップでインタラクティブなコマンドラインツールを構築できるようにし、入力の解析、コマンドの実行、出力のレンダリングをサポートします。スクリプトユーティリティやデバッグツール、またはターミナルコマンドによるユーザーインタラクションが必要な教育アプリケーションに最適です。このパッケージはクロスプラットフォームであり、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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト