snapshot method

VtRenderSnapshot snapshot()

Implementation

VtRenderSnapshot snapshot() {
  _ensureOpen();
  final cols = calloc<ffi.Uint16>();
  final rows = calloc<ffi.Uint16>();
  final dirty = calloc<ffi.UnsignedInt>();
  final colors = calloc<bindings.GhosttyRenderStateColors>();
  final cursorVisualStyle = calloc<ffi.UnsignedInt>();
  final cursorVisible = calloc<ffi.Bool>();
  final cursorBlinking = calloc<ffi.Bool>();
  final passwordInput = calloc<ffi.Bool>();
  final cursorHasValue = calloc<ffi.Bool>();
  final cursorX = calloc<ffi.Uint16>();
  final cursorY = calloc<ffi.Uint16>();
  final cursorWideTail = calloc<ffi.Bool>();
  try {
    colors.ref.size = ffi.sizeOf<bindings.GhosttyRenderStateColors>();
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings.GhosttyRenderStateData.GHOSTTY_RENDER_STATE_DATA_COLS,
        cols.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings.GhosttyRenderStateData.GHOSTTY_RENDER_STATE_DATA_ROWS,
        rows.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings.GhosttyRenderStateData.GHOSTTY_RENDER_STATE_DATA_DIRTY,
        dirty.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_colors_get(_handle, colors),
      'ghostty_render_state_colors_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings
            .GhosttyRenderStateData
            .GHOSTTY_RENDER_STATE_DATA_CURSOR_VISUAL_STYLE,
        cursorVisualStyle.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings
            .GhosttyRenderStateData
            .GHOSTTY_RENDER_STATE_DATA_CURSOR_VISIBLE,
        cursorVisible.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings
            .GhosttyRenderStateData
            .GHOSTTY_RENDER_STATE_DATA_CURSOR_BLINKING,
        cursorBlinking.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings
            .GhosttyRenderStateData
            .GHOSTTY_RENDER_STATE_DATA_CURSOR_PASSWORD_INPUT,
        passwordInput.cast(),
      ),
      'ghostty_render_state_get',
    );
    _checkResult(
      bindings.ghostty_render_state_get(
        _handle,
        bindings
            .GhosttyRenderStateData
            .GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_HAS_VALUE,
        cursorHasValue.cast(),
      ),
      'ghostty_render_state_get',
    );
    if (cursorHasValue.value) {
      _checkResult(
        bindings.ghostty_render_state_get(
          _handle,
          bindings
              .GhosttyRenderStateData
              .GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_X,
          cursorX.cast(),
        ),
        'ghostty_render_state_get',
      );
      _checkResult(
        bindings.ghostty_render_state_get(
          _handle,
          bindings
              .GhosttyRenderStateData
              .GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_Y,
          cursorY.cast(),
        ),
        'ghostty_render_state_get',
      );
      _checkResult(
        bindings.ghostty_render_state_get(
          _handle,
          bindings
              .GhosttyRenderStateData
              .GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_WIDE_TAIL,
          cursorWideTail.cast(),
        ),
        'ghostty_render_state_get',
      );
    }

    return VtRenderSnapshot(
      cols: cols.value,
      rows: rows.value,
      dirty: bindings.GhosttyRenderStateDirty.fromValue(dirty.value),
      colors: VtRenderColors.fromNative(colors.ref),
      cursor: VtRenderCursorSnapshot(
        visualStyle: bindings.GhosttyRenderStateCursorVisualStyle.fromValue(
          cursorVisualStyle.value,
        ),
        visible: cursorVisible.value,
        blinking: cursorBlinking.value,
        passwordInput: passwordInput.value,
        hasViewportPosition: cursorHasValue.value,
        viewportX: cursorHasValue.value ? cursorX.value : null,
        viewportY: cursorHasValue.value ? cursorY.value : null,
        onWideTail: cursorHasValue.value ? cursorWideTail.value : null,
      ),
      rowsData: _snapshotRows(),
    );
  } finally {
    calloc.free(cursorWideTail);
    calloc.free(cursorY);
    calloc.free(cursorX);
    calloc.free(cursorHasValue);
    calloc.free(passwordInput);
    calloc.free(cursorBlinking);
    calloc.free(cursorVisible);
    calloc.free(cursorVisualStyle);
    calloc.free(colors);
    calloc.free(dirty);
    calloc.free(rows);
    calloc.free(cols);
  }
}