resize method

void resize(
  1. int newWidth,
  2. int newHeight, [
  3. int? pixelWidth,
  4. int? pixelHeight,
])

Resize the terminal screen. newWidth and newHeight should be greater than 0. Text reflow is currently not implemented and will be avaliable in the future.

Calls onResize with the arguments first, as xterm does. Both screens resize; the main screen reflows unless reflowEnabled is false. pixelWidth and pixelHeight (xterm's view passes the cell size in logical pixels) also set libghostty-vt's cell size, used in size reports. Must not be called during a frame's build or layout.

Implementation

void resize(
  int newWidth,
  int newHeight, [
  int? pixelWidth,
  int? pixelHeight,
]) {
  newWidth = max(newWidth, 1);
  newHeight = max(newHeight, 1);
  final vt = _vt;

  onResize?.call(newWidth, newHeight, pixelWidth ?? 0, pixelHeight ?? 0);

  final ratio = _internals.viewDevicePixelRatio ?? 1;
  int? devicePixels(int? logical) =>
      logical == null || logical <= 0 ? null : (logical * ratio).round();

  // libghostty-vt reflows the main screen only while autowrap is set.
  final suppressReflow =
      !reflowEnabled && vt.isModeEnabled(TerminalMode.wraparound);
  _resizing = true;
  try {
    if (suppressReflow) {
      vt.setMode(TerminalMode.wraparound, enabled: false);
    }
    try {
      _controller.resize(
        newWidth,
        newHeight,
        cellWidthPx: devicePixels(pixelWidth),
        cellHeightPx: devicePixels(pixelHeight),
      );
    } finally {
      if (suppressReflow && !vt.isDisposed) {
        vt.setMode(TerminalMode.wraparound, enabled: true);
      }
    }
  } finally {
    _resizing = false;
  }
  _applyScrollbackLimit();
  _engine.invalidate();
}