Viewing version 0.1.3. Open the latest package page.

cli_repl

0.1.3

A simple library for creating CLI REPLs

Download archive

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.
Changelog

Changelog

0.1.3

  • Line editing should now work in environments like the Emacs terminal where EscO is used for ANSI-escaped input instead of the more typical Esc[.

  • Fixed issue with the prompt changing to the Node default when running on it.

  • Broadened dependency on the async package to support 2.x.x versions.

0.1.2

  • If compiled to JS and run with Node, Repl.runAsync() should now work. It uses the Node readline library for line editing.

  • Repl.runAsync() now supports running with no terminal, and should operate similarly to how Repl.run() does, both on the Dart VM and on Node.

0.1.1

  • Fix issues on Windows

0.1.0

  • Makes Repl.run() synchronous, since that use case is probably more common. The asynchronous version can now be run with Repl.runAsync().

  • When running with Repl.run() and no terminal, this will no longer crash, and instead print both prompts and the input, allowing you to test a REPL by piping input to it.

  • Adds support for limited cutting and pasting with Ctrl-U, Ctrl-K, and Ctrl-Y.

0.0.1

  • Initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'cli_repl:0.1.3'
pubspec.yaml
name: cli_repl
description: A simple library for creating CLI REPLs
version: 0.1.3
homepage: https://github.com/jathak/cli_repl
author: Jen Thakar <jen@jenthakar.com>

dependencies:
  async: ">=1.13.3 <3.0.0"
  js: ^0.6.1
  io: ^0.3.2

dev_dependencies:
  grinder: ^0.8.1
  node_preamble: ^1.4.0
  test: ^0.12.34
  test_process: ^1.0.1

environment:
  sdk: '>=1.20.1 <2.0.0'

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownload555fec6b…dce580
0.1.1Cached · Upstream SHA-256 matchedDownload2f1d5f16…769907
0.1.1+1Cached · Upstream SHA-256 matchedDownload1d97ae90…bf8b3b
0.1.2Cached · Upstream SHA-256 matchedDownload742f5409…652ff6
0.1.3Cached · Upstream SHA-256 matchedDownloada131f2d5…97195b
0.2.0Cached · Upstream SHA-256 matchedDownload57787b07…f8a8d0
0.2.0+1Cached · Upstream SHA-256 matchedDownloadbb9f00f2…929b00
0.2.1-nullsafetyCached · Upstream SHA-256 matchedDownload405a93c4…b218c7
0.2.1Cached · Upstream SHA-256 matchedDownload8f4ddaa1…1a982b
0.2.2Cached · Upstream SHA-256 matchedDownloadf796c280…5e4bc4
0.2.3Cached · Upstream SHA-256 matchedDownloada2ee06d9…b0ddd4

Dependencies

async "\u003e=1.13.3 \u003c3.0.0"

io "^0.3.2"

js "^0.6.1"