read_line abstract method

String? read_line({
  1. bool cancel_on_break,
  2. bool cancel_on_escape,
  3. bool cancel_on_eof,
  4. void callback(
    1. String text,
    2. Key lastPressed
    )?,
})

Reads a line of input, handling basic keyboard navigation commands.

The Dart stdin.readLineSync() function reads a line from the input, however it does not handle cursor navigation (e.g. arrow keys, home and end keys), and has side-effects that may be unhelpful for certain console applications. For example, Ctrl+C is processed as the break character, which causes the application to immediately exit.

The implementation does not currently allow for multi-line input. It is best suited for short text fields that are not longer than the width of the current screen.

By default, readLine ignores break characters (e.g. Ctrl+C) and the Esc key, but if enabled, the function will exit and return a null string if those keys are pressed.

A callback function may be supplied, as a peek-ahead for what is being entered. This is intended for scenarios like auto-complete, where the text field is coupled with some other content.

Implementation

String? read_line({
  final bool cancel_on_break,
  final bool cancel_on_escape,
  final bool cancel_on_eof,
  final void Function(String text, Key lastPressed)? callback,
});