dart_console 0.1.0+3

A Dart library for building console applications.

pub package

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 is being used to implement a Dart version of the Kilo text editor, and is sufficient for a reasonably complete set of usage, including readline-style CLI and basic text games.

The library assumes a VT-style terminal, as used by macOS and Linux. This package does not currently work on Windows.

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 included in the example/demo.dart and example/command_line.dart files.

Other Notes #

dart_console uses the new FFI capabilities in Dart 2.5 and later. As of the time of writing (August 2019), this is not available in a stable release. However, the package declares a dependency of Dart 2.4 so that dartdoc still works. For this reason, dart_console currently has a low pub.dev analysis score. This should fix itself when pub.dev rolls forward to Dart 2.5.

Dart 2.5 is currently available in the master channel of Flutter or as a standalone download from the Dart SDK install page.

Acknowledgements #

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

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.0+3 #

  • Tidy up documentation and comments.

0.1.0+2 #

  • Revert Dart version dependency, since it broke dartdoc.

0.1.0+1 #

  • Fix Dart version dependency

0.1.0 #

  • Initial version


import 'package:dart_console/dart_console.dart';

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 (ConsoleColor 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.1.0+3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support 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 Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19


Detected platforms:

Low code quality prevents platform classification.

Health issues and suggestions

Fix lib/src/ffi/termlib.dart. (-98.22 points)

Analysis of lib/src/ffi/termlib.dart failed with 14 errors, including:

line 20 col 11: 'TermIOS' doesn't extend 'NativeType'.

line 27 col 13: 'WinSize' doesn't extend 'NativeType'.

line 27 col 47: 'WinSize' doesn't extend 'NativeType'.

line 27 col 56: The class 'Pointer' doesn't have a constructor named 'allocate'.

line 40 col 13: 'WinSize' doesn't extend 'NativeType'.

Fix lib/src/ffi/termios.dart. (-76.27 points)

Analysis of lib/src/ffi/termios.dart failed with 5 errors:

line 70 col 23: The type 'Struct' is declared with 0 type parameters, but 1 type arguments were given.

line 130 col 27: 'TermIOS' doesn't extend 'NativeType'.

line 131 col 58: 'TermIOS' doesn't extend 'NativeType'.

line 135 col 51: 'TermIOS' doesn't extend 'NativeType'.

line 137 col 47: 'TermIOS' doesn't extend 'NativeType'.

Fix lib/src/ffi/ioctl.dart. (-57.81 points)

Analysis of lib/src/ffi/ioctl.dart failed with 3 errors:

line 12 col 23: The type 'Struct' is declared with 0 type parameters, but 1 type arguments were given.

line 27 col 15: 'WinSize' doesn't extend 'NativeType'.

line 27 col 24: The class 'Pointer' doesn't have a constructor named 'allocate'.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.5