apply method

void apply(
  1. GridUpdate u
)

Implementation

void apply(GridUpdate u) {
  _defaultFg = u.defaultFg;
  _defaultBg = u.defaultBg;
  _cursorColor = u.cursorColor;
  // Partial damage only names changed lines; rows/columns on GridUpdate are not
  // viewport size (see FrbEngineBinding._toGridUpdate). Resize on full only.
  if (u.full) {
    _ensureSize(u.rows, u.columns);
  }
  for (final l in u.lines) {
    if (l.line < 0 || l.line >= _rows) continue;
    // Partial damage can arrive with engine cols > mirror cols when resize races
    // the async drain (LayoutBuilder grew before post-frame resize ran).
    final copy = l.codepoints.length < _columns ? l.codepoints.length : _columns;
    if (copy == 0) continue;
    _codepoints[l.line].setRange(0, copy, l.codepoints);
    _fg[l.line].setRange(0, copy, l.fg);
    _bg[l.line].setRange(0, copy, l.bg);
    _flags[l.line].setRange(0, copy, l.flags);
    _hyperlinkId[l.line].setRange(0, copy, l.hyperlinkId);
  }
  // Overscan row only arrives on full updates; partial damage always carries
  // scrollFraction 0 (engine forces a full snapshot whenever it's non-zero),
  // so the row-(-1) data the painter reads is never stale while visible.
  final o = u.overscan;
  if (o != null) {
    final copy = o.codepoints.length < _columns ? o.codepoints.length : _columns;
    _overCodepoints.fillRange(0, _columns, 32);
    _overFg.fillRange(0, _columns, _defaultFg);
    _overBg.fillRange(0, _columns, _defaultBg);
    _overFlags.fillRange(0, _columns, 0);
    _overHyperlinkId.fillRange(0, _columns, 0);
    if (copy > 0) {
      _overCodepoints.setRange(0, copy, o.codepoints);
      _overFg.setRange(0, copy, o.fg);
      _overBg.setRange(0, copy, o.bg);
      _overFlags.setRange(0, copy, o.flags);
      _overHyperlinkId.setRange(0, copy, o.hyperlinkId);
    }
  }
  _scrollFraction = u.scrollFraction;
  _cursorRow = u.cursorRow;
  _cursorCol = u.cursorCol;
  _cursorVisible = u.cursorVisible;
  _cursorShape = u.cursorShape;
  _cursorBlinking = u.cursorBlinking;
  _modeFlags = u.modeFlags;
  _displayOffset = u.displayOffset;
  _generation++;
  notifyListeners();
}