cli_repl 0.2.0+1

  • Example
  • Installing
  • Versions
  • 84


A simple library for creating CLI REPLs in Dart.


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.


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.



  • Support Dart 2 stable.


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


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


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


  • Fix issues on Windows


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


  • 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 packages get

Alternatively, your editor might support pub get or flutter packages 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';
Version Uploaded Documentation Archive
0.2.0+1 Aug 3, 2018 Go to the documentation of cli_repl 0.2.0+1 Download cli_repl 0.2.0+1 archive
0.2.0 Jun 19, 2018 Go to the documentation of cli_repl 0.2.0 Download cli_repl 0.2.0 archive
0.1.3 May 8, 2018 Go to the documentation of cli_repl 0.1.3 Download cli_repl 0.1.3 archive
0.1.2 Apr 15, 2018 Go to the documentation of cli_repl 0.1.2 Download cli_repl 0.1.2 archive
0.1.1+1 Apr 14, 2018 Go to the documentation of cli_repl 0.1.1+1 Download cli_repl 0.1.1+1 archive
0.1.1 Apr 14, 2018 Go to the documentation of cli_repl 0.1.1 Download cli_repl 0.1.1 archive
0.0.1 Apr 5, 2018 Go to the documentation of cli_repl 0.0.1 Download cli_repl 0.0.1 archive
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 Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:cli_repl/cli_repl.dart.

Health suggestions

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

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

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

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

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

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

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

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.


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