dart_console 0.5.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

A Dart library for building console applications.

pub package Language

This library contains a variety of useful functions for console application development, including:

  • Reading the current window dimensions (height, width)
  • Reading and setting the cursor location
  • Setting foreground and background colors
  • Manipulating the console into "raw mode", which allows more advanced keyboard input processing than the default dart:io library.
  • Reading keys and control sequences from the keyboard
  • Writing aligned text to the screen

The library has been used to implement a Dart version of the Kilo text editor; when compiled with dart2native that results in a self-contained kilo executable. The library is sufficient for a reasonably complete set of usage, including readline-style CLI and basic text games.

The library assumes a terminal that recognizes and implements common ANSI escape sequences. The package has been tested on macOS, Linux and Windows 10 version 1903. Windows support is preliminary - the library is tested on the Windows Terminal and cmd, but some functions will not work on older versions of Windows that do not support ANSI escape sequences.

As an aside, this library demonstrates usage of the dart:ffi library for calling system APIs and separating Win32 and UNIX-style implementations.

Usage #

A simple example for the dart_console package:

import 'package:dart_console/dart_console.dart';

main() {
  final console = Console();


      'Console size is ${console.windowWidth} cols and ${console.windowHeight} rows.',

  return 0;

More comprehensive demos of the Console class are provided, as follows:

demo.dartSuite of test demos that showcase various capabilities
main.dartBasic demo of how to get started with the dart_console
keys.dartDemonstrates how dart_console processes control characters
readline.dartSample command-line interface / REPL
kilo.dartRudimentary text editor
life.dartGame of Life

Acknowledgements #

Special thanks to Matt Sullivan (@mjohnsullivan) and Samir Jindel (@sjindel-google) for their help understanding the vagaries of FFI in its early state.

Thanks to @erf for contributing the Game of Life example.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.5.0-dev.2 #

  • Add writeErrorLine function which writes to stderr
  • BREAKING: Automatically print a new line to the console after every readLine input
  • BREAKING: readLine now returns a null string, rather than an empty string, when Ctrl+Break or Escape are pressed.
  • Add Game of Life example (thanks to @erf)

0.4.0 #

  • Update to new FFI API

0.3.0 #

  • Add support for Windows consoles that recognize ANSI escape sequences

0.2.0 #

  • Add readline function and escape character support

0.1.0 #

  • Initial version


import 'package:dart_console/dart_console.dart';

void main() {
  final console = Console();
  console.writeLine('Simple Demo', TextAlignment.center);


  console.writeLine('This console window has ${console.windowWidth} cols and '
      '${console.windowHeight} rows.');

  console.writeLine('This text is left aligned.', TextAlignment.left);
  console.writeLine('This text is center aligned.', TextAlignment.center);
  console.writeLine('This text is right aligned.', TextAlignment.right);

  for (var color in ConsoleColor.values) {

Use this package as a library

1. Depend on it

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

  dart_console: ^0.5.0

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:dart_console/dart_console.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 Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev.8.2 <3.0.0
ffi ^0.1.3 0.1.3
Dev dependencies
pedantic ^1.9.0
test ^1.9.4