attach method

void attach({
  1. Stream<TerminalTextSize>? textSizeChanges,
})

Starts watching everything that can change the terminal's geometry.

textSizeChanges re-applies the font live when the preference changes.

Implementation

void attach({Stream<TerminalTextSize>? textSizeChanges}) {
  _detachResize = _on(web.window, 'resize', scheduleFit);
  // The soft keyboard resizes the *visual* viewport, not the window, so refit
  // on its changes too.
  final vv = web.window.visualViewport;
  if (vv != null) {
    _detachViewport = _on(vv, 'resize', scheduleSettle);
  }
  // The robust trigger: refit whenever the host actually changes size
  // (fullscreen toggle, keyboard, rotation, …). A ResizeObserver fires *after*
  // layout, so xterm measures the settled box rather than the previous one.
  final ro = web.ResizeObserver(
    ((JSArray<web.ResizeObserverEntry> entries, web.ResizeObserver observer) {
      scheduleFit();
    }).toJS,
  );
  ro.observe(host);
  _resizeObserver = ro;
  _textSizeSub = textSizeChanges?.listen((_) => scheduleFit());
}