input property

  1. @override
Stream<List<int>> get input
override

Raw input bytes from the terminal.

Implementations must allow this stream to be listened to multiple times in sequence (one listener at a time), so several components can read input one after another.

Implementation

@override
Stream<List<int>> get input {
  final existing = _inputController;
  if (existing != null) return existing.stream;

  // The source subscription is paused whenever no component is listening, so
  // it does not drain input between components. Draining would both discard
  // bytes meant for other readers and, on the real stdin, make a synchronous
  // `readLineSync` (used by other prompt logic) block forever. Resuming on the
  // first listener and pausing again when the last one leaves keeps stdin
  // available for non-inline-tui input in between.
  final controller = StreamController<List<int>>.broadcast(
    onListen: () => _inputSubscription?.resume(),
    onCancel: () => _inputSubscription?.pause(),
  );
  // Listen to the single-subscription source exactly once and forward every
  // event to the broadcast controller. The controller stays open as listeners
  // come and go, so each component can subscribe in turn. It starts paused
  // until the first listener subscribes (see above).
  _inputSubscription = _inputSource.listen(
    controller.add,
    onError: controller.addError,
    onDone: () => unawaited(controller.close()),
  )..pause();
  _inputController = controller;
  return controller.stream;
}