read method

Future<String?> read()

Reads one message. Returns null when the user exits (Ctrl-C twice or Ctrl-D on an empty line, or the end of piped input).

Implementation

Future<String?> read() async {
  if (!_terminal.interactive) {
    return _terminal.readLine();
  }
  _editor.clear();
  _pastes.clear();
  _historyIndex = _history.length;
  _draft = '';
  _selected = 0;
  _showShortcuts = false;
  _setNotice(null);
  final result = _result = Completer<String?>();
  _render();
  final stopListening = _terminal.listen((event) {
    if (!result.isCompleted) {
      _handle(event);
    }
    return true;
  });
  final value = await result.future;
  stopListening();
  _setNotice(null);
  console.live.clear();
  return value;
}