close method

Future<void> close()

Ends the inline session where one is open, what write left without a line break written first, so the terminal is restored with the cursor below the output; then flushes the terminal and closes it (CliTerminal.close): stdin is let go of where a plain prompt read it, so the process can end. Calling it again does nothing more. Cli.run calls it.

Implementation

Future<void> close() async {
  if (_closed) {
    return;
  }
  _closed = true;
  final opening = _opening;
  CliSession? session;
  if (opening != null) {
    try {
      session = await opening;
    } on Object {
      // it failed to open: its asker was told, and there is none to end
      session = null;
    }
  }
  if (session != null) {
    if (_partial.isNotEmpty && session.isOpen) {
      unawaited(
        session.commit(
          _linesWidget(messageLines(_partial.toString(), const Style())),
        ),
      );
      _partial.clear();
    }
    _session = null;
    await session.close();
  }
  if (_partial.isNotEmpty) {
    terminal.out.write(_partial.toString());
    _partial.clear();
  }
  await terminal.flush();
  await terminal.close();
}