write method

void write(
  1. String data
)

Writes the data from the underlying program to the terminal. Calling this updates the states of the terminal and emits events such as onBell or onTitleChange when the escape sequences in data request it.

Implementation

void write(String data) {
  // Fast path: if the chunk contains nothing the parser would dispatch on
  // (no escape byte, no C0 control characters, no dangling surrogate half)
  // and the parser isn't holding back bytes from a previous chunk, write
  // directly to the buffer, bypassing the parser state machine. This is
  // the common case for plain-text output floods.
  if (!_parser.hasPendingInput && !_requiresParser(data)) {
    // Keep _precedingCodepoint in sync so CSI n b (REP) still works after
    // a fast-path write; writeChar would normally maintain it. Extracted
    // via codeUnitAt instead of data.runes.last, which allocates a Runes
    // iterable and scans the whole chunk to find the last code point.
    if (data.isNotEmpty) {
      _precedingCodepoint = _lastCodepoint(data);
    }
    _buffer.write(data);
    notifyListeners();
    return;
  }
  _parser.write(data);
  notifyListeners();
}