cli_repl 0.2.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

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()) {

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.

  • 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 will throw an error.

Changelog #

0.2.0+1 #

  • Support Dart 2 stable.

0.2.0 #

  • Removes option to use sharedStdIn, as well as the io package dependency.

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 does, both on the Dart VM and on Node.

0.1.1 #

  • Fix issues on Windows

0.1.0 #

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

  • When running with 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


/// Example REPL that looks for a semicolon to complete a statement and then
/// echoes all completed statements.

import 'package:cli_repl/cli_repl.dart';

main(args) async {
  var v = (str) => str.trim().isEmpty || str.trim().endsWith(';');
  var repl = new Repl(prompt: '>>> ', continuation: '... ', validator: v);
  await for (var x in repl.runAsync()) {
    if (x.trim().isEmpty) continue;

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  cli_repl: ^0.2.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:cli_repl/cli_repl.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/repl_adapter/node.dart. (-5.84 points)

Analysis of lib/src/repl_adapter/node.dart reported 12 hints, including:

line 14 col 11: Unnecessary new keyword.

line 22 col 9: Unnecessary new keyword.

line 25 col 22: Unnecessary new keyword.

line 26 col 17: Unnecessary new keyword.

line 53 col 1: The @JS() annotation can only be used if it is also declared on the library directive.

Fix lib/src/repl_adapter/vm.dart. (-4.41 points)

Analysis of lib/src/repl_adapter/vm.dart reported 9 hints, including:

line 59 col 17: Unnecessary new keyword.

line 82 col 25: Avoid empty catch blocks.

line 227 col 27: Unnecessary new keyword.

line 257 col 11: Unnecessary new keyword.

line 271 col 11: Unnecessary new keyword.

Fix lib/cli_repl.dart. (-1.49 points)

Analysis of lib/cli_repl.dart reported 3 hints:

line 19 col 19: Use = to separate a named parameter from its default value.

line 22 col 22: Use = to separate a named parameter from its default value.

line 25 col 16: Unnecessary new keyword.

Fix lib/src/repl_adapter/codes.dart. (-0.50 points)

Analysis of lib/src/repl_adapter/codes.dart reported 1 hint:

line 23 col 27: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-64.66 points)

The package was last published 85 weeks ago.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
async >=1.13.3 <3.0.0 2.4.1
js ^0.6.1 0.6.1+1
Transitive dependencies
collection 1.14.12
Dev dependencies
grinder ^0.8.1
node_preamble ^1.4.0
test >=0.12.34 <2.0.0
test_process ^1.0.1