VtCellSnapshot.fromRaw constructor

VtCellSnapshot.fromRaw(
  1. DartGhosttyCell cell
)

Implementation

factory VtCellSnapshot.fromRaw(bindings.DartGhosttyCell cell) {
  int getUint32(bindings.GhosttyCellData data) {
    final out = calloc<ffi.Uint32>();
    try {
      _checkResult(
        bindings.ghostty_cell_get(cell, data, out.cast()),
        'cell_get',
      );
      return out.value;
    } finally {
      calloc.free(out);
    }
  }

  bool getBool(bindings.GhosttyCellData data) {
    final out = calloc<ffi.Bool>();
    try {
      _checkResult(
        bindings.ghostty_cell_get(cell, data, out.cast()),
        'cell_get',
      );
      return out.value;
    } finally {
      calloc.free(out);
    }
  }

  final contentTag = bindings.GhosttyCellContentTag.fromValue(
    getUint32(bindings.GhosttyCellData.GHOSTTY_CELL_DATA_CONTENT_TAG),
  );
  final colorPaletteIndex =
      contentTag ==
          bindings.GhosttyCellContentTag.GHOSTTY_CELL_CONTENT_BG_COLOR_PALETTE
      ? (() {
          final out = calloc<ffi.Uint8>();
          try {
            _checkResult(
              bindings.ghostty_cell_get(
                cell,
                bindings.GhosttyCellData.GHOSTTY_CELL_DATA_COLOR_PALETTE,
                out.cast(),
              ),
              'cell_get',
            );
            return out.value;
          } finally {
            calloc.free(out);
          }
        })()
      : null;
  final colorRgb =
      contentTag ==
          bindings.GhosttyCellContentTag.GHOSTTY_CELL_CONTENT_BG_COLOR_RGB
      ? (() {
          final out = calloc<bindings.GhosttyColorRgb>();
          try {
            _checkResult(
              bindings.ghostty_cell_get(
                cell,
                bindings.GhosttyCellData.GHOSTTY_CELL_DATA_COLOR_RGB,
                out.cast(),
              ),
              'cell_get',
            );
            return _rgbFromNative(out.ref);
          } finally {
            calloc.free(out);
          }
        })()
      : null;

  return VtCellSnapshot(
    codepoint: getUint32(
      bindings.GhosttyCellData.GHOSTTY_CELL_DATA_CODEPOINT,
    ),
    contentTag: contentTag,
    wide: bindings.GhosttyCellWide.fromValue(
      getUint32(bindings.GhosttyCellData.GHOSTTY_CELL_DATA_WIDE),
    ),
    hasText: getBool(bindings.GhosttyCellData.GHOSTTY_CELL_DATA_HAS_TEXT),
    hasStyling: getBool(
      bindings.GhosttyCellData.GHOSTTY_CELL_DATA_HAS_STYLING,
    ),
    styleId: (() {
      final out = calloc<ffi.Uint16>();
      try {
        _checkResult(
          bindings.ghostty_cell_get(
            cell,
            bindings.GhosttyCellData.GHOSTTY_CELL_DATA_STYLE_ID,
            out.cast(),
          ),
          'cell_get',
        );
        return out.value;
      } finally {
        calloc.free(out);
      }
    })(),
    hasHyperlink: getBool(
      bindings.GhosttyCellData.GHOSTTY_CELL_DATA_HAS_HYPERLINK,
    ),
    isProtected: getBool(
      bindings.GhosttyCellData.GHOSTTY_CELL_DATA_PROTECTED,
    ),
    semanticContent: bindings.GhosttyCellSemanticContent.fromValue(
      getUint32(bindings.GhosttyCellData.GHOSTTY_CELL_DATA_SEMANTIC_CONTENT),
    ),
    colorPaletteIndex: colorPaletteIndex,
    colorRgb: colorRgb,
  );
}