···11+package libghostty
22+33+// Shared helpers for the get_multi pattern used by multiple types.
44+// These helpers solve the cgo pointer-passing rule: Go cannot pass
55+// a Go-allocated void** (array of pointers to Go memory) directly
66+// to C. Instead, we allocate the void** array in C heap memory,
77+// copy the Go pointer values in, call the C function, then free.
88+99+/*
1010+#include <stdlib.h>
1111+*/
1212+import "C"
1313+1414+import "unsafe"
1515+1616+// cValuesArray allocates a C-heap array of void* pointers, copies the
1717+// Go unsafe.Pointer values into it, and returns the C array pointer.
1818+// The caller must free the returned pointer with C.free when done.
1919+func cValuesArray(values []unsafe.Pointer) *unsafe.Pointer {
2020+ n := len(values)
2121+ cArr := (*unsafe.Pointer)(C.malloc(C.size_t(n) * C.size_t(unsafe.Sizeof(unsafe.Pointer(nil)))))
2222+ dst := unsafe.Slice(cArr, n)
2323+ copy(dst, values)
2424+ return cArr
2525+}
+311-51
kitty_graphics.go
···55// protocol.
6677/*
88+#include <stdlib.h>
89#include <ghostty/vt.h>
9101011// Helper to create a properly initialized GhosttySelection (sized struct).
···1314 return s;
1415}
15161616-// Helper to create a properly initialized GhosttyKittyGraphicsImageInfo (sized struct).
1717-static inline GhosttyKittyGraphicsImageInfo init_kitty_image_info() {
1818- GhosttyKittyGraphicsImageInfo info = GHOSTTY_INIT_SIZED(GhosttyKittyGraphicsImageInfo);
1919- return info;
2020-}
2121-2222-// Helper to create a properly initialized GhosttyKittyGraphicsPlacementInfo (sized struct).
2323-static inline GhosttyKittyGraphicsPlacementInfo init_kitty_placement_info() {
2424- GhosttyKittyGraphicsPlacementInfo info = GHOSTTY_INIT_SIZED(GhosttyKittyGraphicsPlacementInfo);
2525- return info;
2626-}
2727-2817// Helper to create a properly initialized GhosttyKittyGraphicsPlacementRenderInfo (sized struct).
2918static inline GhosttyKittyGraphicsPlacementRenderInfo init_kitty_placement_render_info() {
3019 GhosttyKittyGraphicsPlacementRenderInfo info = GHOSTTY_INIT_SIZED(GhosttyKittyGraphicsPlacementRenderInfo);
···3322*/
3423import "C"
35243636-import "unsafe"
2525+import (
2626+ "errors"
2727+ "unsafe"
2828+)
2929+3030+// KittyGraphicsImageData identifies a data field for Kitty graphics
3131+// image queries.
3232+// C: GhosttyKittyGraphicsImageData
3333+type KittyGraphicsImageData int
3434+3535+const (
3636+ // KittyGraphicsImageDataInvalid is an invalid / sentinel value.
3737+ KittyGraphicsImageDataInvalid KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_INVALID
3838+3939+ // KittyGraphicsImageDataID is the image ID (uint32_t).
4040+ KittyGraphicsImageDataID KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_ID
4141+4242+ // KittyGraphicsImageDataNumber is the image number (uint32_t).
4343+ KittyGraphicsImageDataNumber KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_NUMBER
4444+4545+ // KittyGraphicsImageDataWidth is the image width in pixels (uint32_t).
4646+ KittyGraphicsImageDataWidth KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_WIDTH
4747+4848+ // KittyGraphicsImageDataHeight is the image height in pixels (uint32_t).
4949+ KittyGraphicsImageDataHeight KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_HEIGHT
5050+5151+ // KittyGraphicsImageDataFormat is the pixel format of the image
5252+ // (GhosttyKittyImageFormat).
5353+ KittyGraphicsImageDataFormat KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_FORMAT
5454+5555+ // KittyGraphicsImageDataCompression is the compression of the image
5656+ // (GhosttyKittyImageCompression).
5757+ KittyGraphicsImageDataCompression KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_COMPRESSION
5858+5959+ // KittyGraphicsImageDataDataPtr is a borrowed pointer to the raw pixel
6060+ // data (const uint8_t **).
6161+ KittyGraphicsImageDataDataPtr KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR
6262+6363+ // KittyGraphicsImageDataDataLen is the length of the raw pixel data
6464+ // in bytes (size_t).
6565+ KittyGraphicsImageDataDataLen KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_DATA_LEN
6666+)
6767+6868+// KittyGraphicsPlacementData identifies a data field for Kitty graphics
6969+// placement queries.
7070+// C: GhosttyKittyGraphicsPlacementData
7171+type KittyGraphicsPlacementData int
7272+7373+const (
7474+ // KittyGraphicsPlacementDataInvalid is an invalid / sentinel value.
7575+ KittyGraphicsPlacementDataInvalid KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INVALID
7676+7777+ // KittyGraphicsPlacementDataImageID is the image ID this placement
7878+ // belongs to (uint32_t).
7979+ KittyGraphicsPlacementDataImageID KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID
8080+8181+ // KittyGraphicsPlacementDataPlacementID is the placement ID (uint32_t).
8282+ KittyGraphicsPlacementDataPlacementID KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID
8383+8484+ // KittyGraphicsPlacementDataIsVirtual indicates whether this is a
8585+ // virtual placement (bool).
8686+ KittyGraphicsPlacementDataIsVirtual KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL
8787+8888+ // KittyGraphicsPlacementDataXOffset is the pixel offset from the left
8989+ // edge of the cell (uint32_t).
9090+ KittyGraphicsPlacementDataXOffset KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET
9191+9292+ // KittyGraphicsPlacementDataYOffset is the pixel offset from the top
9393+ // edge of the cell (uint32_t).
9494+ KittyGraphicsPlacementDataYOffset KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET
9595+9696+ // KittyGraphicsPlacementDataSourceX is the source rectangle x origin
9797+ // in pixels (uint32_t).
9898+ KittyGraphicsPlacementDataSourceX KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X
9999+100100+ // KittyGraphicsPlacementDataSourceY is the source rectangle y origin
101101+ // in pixels (uint32_t).
102102+ KittyGraphicsPlacementDataSourceY KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y
103103+104104+ // KittyGraphicsPlacementDataSourceWidth is the source rectangle width
105105+ // in pixels (uint32_t).
106106+ KittyGraphicsPlacementDataSourceWidth KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH
107107+108108+ // KittyGraphicsPlacementDataSourceHeight is the source rectangle height
109109+ // in pixels (uint32_t).
110110+ KittyGraphicsPlacementDataSourceHeight KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT
111111+112112+ // KittyGraphicsPlacementDataColumns is the number of columns this
113113+ // placement occupies (uint32_t).
114114+ KittyGraphicsPlacementDataColumns KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS
115115+116116+ // KittyGraphicsPlacementDataRows is the number of rows this placement
117117+ // occupies (uint32_t).
118118+ KittyGraphicsPlacementDataRows KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS
119119+120120+ // KittyGraphicsPlacementDataZ is the z-index for this placement
121121+ // (int32_t).
122122+ KittyGraphicsPlacementDataZ KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z
123123+)
3712438125// KittyGraphics is a handle to the Kitty graphics image storage
39126// associated with a terminal's active screen. It is borrowed from
···146233}
147234148235// KittyGraphicsImageInfo contains all image metadata in a single struct.
149149-// This is more efficient than querying each field individually since it
150150-// requires only one cgo call.
151151-//
152152-// C: GhosttyKittyGraphicsImageInfo
236236+// This is a Go-only convenience type; it has no corresponding C struct.
237237+// Populated via get_multi in a single cgo call.
153238type KittyGraphicsImageInfo struct {
154239 // ID is the image ID.
155240 ID uint32
···175260}
176261177262// KittyGraphicsPlacementInfo contains all placement metadata in a single
178178-// struct. This is more efficient than querying each field individually
179179-// since it requires only one cgo call.
180180-//
181181-// C: GhosttyKittyGraphicsPlacementInfo
263263+// struct. This is a Go-only convenience type; it has no corresponding
264264+// C struct. Populated via get_multi in a single cgo call.
182265type KittyGraphicsPlacementInfo struct {
183266 // ImageID is the image ID this placement belongs to.
184267 ImageID uint32
···334417 return uint32(v), nil
335418}
336419420420+// GetMulti queries multiple image data fields in a single cgo call.
421421+// This is a low-level function; prefer the typed getters (ID, Width,
422422+// Height, Format, etc.) or Info() for normal use. GetMulti is useful
423423+// when you need a custom subset of fields and want to avoid per-field
424424+// cgo overhead.
425425+//
426426+// Each element in keys specifies a data kind, and the corresponding
427427+// element in values must be an unsafe.Pointer to a variable whose type
428428+// matches the "Output type" documented for that key in the upstream C
429429+// header (ghostty/vt/kitty_graphics.h, GhosttyKittyGraphicsImageData
430430+// enum).
431431+//
432432+// Example:
433433+//
434434+// var w, h C.uint32_t
435435+// err := img.GetMulti(
436436+// []KittyGraphicsImageData{KittyGraphicsImageDataWidth, KittyGraphicsImageDataHeight},
437437+// []unsafe.Pointer{unsafe.Pointer(&w), unsafe.Pointer(&h)},
438438+// )
439439+//
440440+// C: ghostty_kitty_graphics_image_get_multi
441441+func (img *KittyGraphicsImage) GetMulti(keys []KittyGraphicsImageData, values []unsafe.Pointer) error {
442442+ if len(keys) != len(values) {
443443+ return errors.New("libghostty: keys and values must have the same length")
444444+ }
445445+ if len(keys) == 0 {
446446+ return nil
447447+ }
448448+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
449449+ cVals := cValuesArray(values)
450450+ defer C.free(unsafe.Pointer(cVals))
451451+ return resultError(C.ghostty_kitty_graphics_image_get_multi(
452452+ img.ptr,
453453+ C.size_t(len(keys)),
454454+ (*C.GhosttyKittyGraphicsImageData)(unsafe.Pointer(&keys[0])),
455455+ cVals,
456456+ nil,
457457+ ))
458458+}
459459+337460// Format returns the pixel format of the image.
338461func (img *KittyGraphicsImage) Format() (KittyImageFormat, error) {
339462 var v C.GhosttyKittyImageFormat
···362485363486// Info returns all image metadata in a single call. This is more
364487// efficient than calling ID, Number, Width, Height, Format,
365365-// Compression, and Data individually.
488488+// Compression, and Data individually. Uses the get_multi C API
489489+// to fetch all fields in one cgo round-trip.
366490func (img *KittyGraphicsImage) Info() (*KittyGraphicsImageInfo, error) {
367367- ci := C.init_kitty_image_info()
368368- if err := resultError(C.ghostty_kitty_graphics_image_get(
491491+ // Output variables — one per field, typed to match the C API.
492492+ var (
493493+ id C.uint32_t
494494+ number C.uint32_t
495495+ width C.uint32_t
496496+ height C.uint32_t
497497+ format C.GhosttyKittyImageFormat
498498+ compression C.GhosttyKittyImageCompression
499499+ dataPtr *C.uint8_t
500500+ dataLen C.size_t
501501+ )
502502+503503+ // Keys identify which fields to fetch; order must match values.
504504+ keys := [...]C.GhosttyKittyGraphicsImageData{
505505+ C.GHOSTTY_KITTY_IMAGE_DATA_ID,
506506+ C.GHOSTTY_KITTY_IMAGE_DATA_NUMBER,
507507+ C.GHOSTTY_KITTY_IMAGE_DATA_WIDTH,
508508+ C.GHOSTTY_KITTY_IMAGE_DATA_HEIGHT,
509509+ C.GHOSTTY_KITTY_IMAGE_DATA_FORMAT,
510510+ C.GHOSTTY_KITTY_IMAGE_DATA_COMPRESSION,
511511+ C.GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR,
512512+ C.GHOSTTY_KITTY_IMAGE_DATA_DATA_LEN,
513513+ }
514514+515515+ // Each value pointer receives the corresponding field from C.
516516+ // We must allocate the void** array in C memory to satisfy cgo
517517+ // pointer-passing rules (Go cannot pass a Go pointer containing
518518+ // other Go pointers to C).
519519+ values := [...]unsafe.Pointer{
520520+ unsafe.Pointer(&id),
521521+ unsafe.Pointer(&number),
522522+ unsafe.Pointer(&width),
523523+ unsafe.Pointer(&height),
524524+ unsafe.Pointer(&format),
525525+ unsafe.Pointer(&compression),
526526+ unsafe.Pointer(&dataPtr),
527527+ unsafe.Pointer(&dataLen),
528528+ }
529529+ cVals := cValuesArray(values[:])
530530+ defer C.free(unsafe.Pointer(cVals))
531531+532532+ if err := resultError(C.ghostty_kitty_graphics_image_get_multi(
369533 img.ptr,
370370- C.GHOSTTY_KITTY_IMAGE_DATA_INFO,
371371- unsafe.Pointer(&ci),
534534+ C.size_t(len(keys)),
535535+ &keys[0],
536536+ cVals,
537537+ nil,
372538 )); err != nil {
373539 return nil, err
374540 }
375541376542 info := &KittyGraphicsImageInfo{
377377- ID: uint32(ci.id),
378378- Number: uint32(ci.number),
379379- Width: uint32(ci.width),
380380- Height: uint32(ci.height),
381381- Format: KittyImageFormat(ci.format),
382382- Compression: KittyImageCompression(ci.compression),
543543+ ID: uint32(id),
544544+ Number: uint32(number),
545545+ Width: uint32(width),
546546+ Height: uint32(height),
547547+ Format: KittyImageFormat(format),
548548+ Compression: KittyImageCompression(compression),
383549 }
384550385385- if ci.data_ptr != nil && ci.data_len > 0 {
386386- info.Data = unsafe.Slice((*byte)(unsafe.Pointer(ci.data_ptr)), int(ci.data_len))
551551+ if dataPtr != nil && dataLen > 0 {
552552+ info.Data = unsafe.Slice((*byte)(unsafe.Pointer(dataPtr)), int(dataLen))
387553 }
388554389555 return info, nil
···453619 return bool(C.ghostty_kitty_graphics_placement_next(it.ptr))
454620}
455621622622+// GetMulti queries multiple placement data fields in a single cgo
623623+// call. This is a low-level function; prefer the typed getters
624624+// (ImageID, PlacementID, Z, etc.) or Info() for normal use. GetMulti
625625+// is useful when you need a custom subset of fields and want to avoid
626626+// per-field cgo overhead.
627627+//
628628+// Each element in keys specifies a data kind, and the corresponding
629629+// element in values must be an unsafe.Pointer to a variable whose type
630630+// matches the "Output type" documented for that key in the upstream C
631631+// header (ghostty/vt/kitty_graphics.h,
632632+// GhosttyKittyGraphicsPlacementData enum).
633633+//
634634+// Example:
635635+//
636636+// var imageID C.uint32_t
637637+// var z C.int32_t
638638+// err := it.GetMulti(
639639+// []KittyGraphicsPlacementData{KittyGraphicsPlacementDataImageID, KittyGraphicsPlacementDataZ},
640640+// []unsafe.Pointer{unsafe.Pointer(&imageID), unsafe.Pointer(&z)},
641641+// )
642642+//
643643+// C: ghostty_kitty_graphics_placement_get_multi
644644+func (it *KittyGraphicsPlacementIterator) GetMulti(keys []KittyGraphicsPlacementData, values []unsafe.Pointer) error {
645645+ if len(keys) != len(values) {
646646+ return errors.New("libghostty: keys and values must have the same length")
647647+ }
648648+ if len(keys) == 0 {
649649+ return nil
650650+ }
651651+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
652652+ cVals := cValuesArray(values)
653653+ defer C.free(unsafe.Pointer(cVals))
654654+ return resultError(C.ghostty_kitty_graphics_placement_get_multi(
655655+ it.ptr,
656656+ C.size_t(len(keys)),
657657+ (*C.GhosttyKittyGraphicsPlacementData)(unsafe.Pointer(&keys[0])),
658658+ cVals,
659659+ nil,
660660+ ))
661661+}
662662+456663// ImageID returns the image ID of the current placement.
457664func (it *KittyGraphicsPlacementIterator) ImageID() (uint32, error) {
458665 var v C.uint32_t
···615822// Info returns all placement metadata in a single call. This is more
616823// efficient than calling ImageID, PlacementID, IsVirtual, XOffset,
617824// YOffset, SourceX, SourceY, SourceWidth, SourceHeight, Columns,
618618-// Rows, and Z individually.
825825+// Rows, and Z individually. Uses the get_multi C API to fetch all
826826+// fields in one cgo round-trip.
619827func (it *KittyGraphicsPlacementIterator) Info() (*KittyGraphicsPlacementInfo, error) {
620620- ci := C.init_kitty_placement_info()
621621- if err := resultError(C.ghostty_kitty_graphics_placement_get(
828828+ // Output variables — one per field, typed to match the C API.
829829+ var (
830830+ imageID C.uint32_t
831831+ placementID C.uint32_t
832832+ isVirtual C.bool
833833+ xOffset C.uint32_t
834834+ yOffset C.uint32_t
835835+ sourceX C.uint32_t
836836+ sourceY C.uint32_t
837837+ sourceWidth C.uint32_t
838838+ sourceHeight C.uint32_t
839839+ columns C.uint32_t
840840+ rows C.uint32_t
841841+ z C.int32_t
842842+ )
843843+844844+ // Keys identify which fields to fetch; order must match values.
845845+ keys := [...]C.GhosttyKittyGraphicsPlacementData{
846846+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID,
847847+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID,
848848+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL,
849849+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET,
850850+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET,
851851+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X,
852852+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y,
853853+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH,
854854+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT,
855855+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS,
856856+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS,
857857+ C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z,
858858+ }
859859+860860+ // Each value pointer receives the corresponding field from C.
861861+ // Allocated in C memory to satisfy cgo pointer-passing rules.
862862+ values := [...]unsafe.Pointer{
863863+ unsafe.Pointer(&imageID),
864864+ unsafe.Pointer(&placementID),
865865+ unsafe.Pointer(&isVirtual),
866866+ unsafe.Pointer(&xOffset),
867867+ unsafe.Pointer(&yOffset),
868868+ unsafe.Pointer(&sourceX),
869869+ unsafe.Pointer(&sourceY),
870870+ unsafe.Pointer(&sourceWidth),
871871+ unsafe.Pointer(&sourceHeight),
872872+ unsafe.Pointer(&columns),
873873+ unsafe.Pointer(&rows),
874874+ unsafe.Pointer(&z),
875875+ }
876876+ cVals := cValuesArray(values[:])
877877+ defer C.free(unsafe.Pointer(cVals))
878878+879879+ if err := resultError(C.ghostty_kitty_graphics_placement_get_multi(
622880 it.ptr,
623623- C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INFO,
624624- unsafe.Pointer(&ci),
881881+ C.size_t(len(keys)),
882882+ &keys[0],
883883+ cVals,
884884+ nil,
625885 )); err != nil {
626886 return nil, err
627887 }
628888629889 return &KittyGraphicsPlacementInfo{
630630- ImageID: uint32(ci.image_id),
631631- PlacementID: uint32(ci.placement_id),
632632- IsVirtual: bool(ci.is_virtual),
633633- XOffset: uint32(ci.x_offset),
634634- YOffset: uint32(ci.y_offset),
635635- SourceX: uint32(ci.source_x),
636636- SourceY: uint32(ci.source_y),
637637- SourceWidth: uint32(ci.source_width),
638638- SourceHeight: uint32(ci.source_height),
639639- Columns: uint32(ci.columns),
640640- Rows: uint32(ci.rows),
641641- Z: int32(ci.z),
890890+ ImageID: uint32(imageID),
891891+ PlacementID: uint32(placementID),
892892+ IsVirtual: bool(isVirtual),
893893+ XOffset: uint32(xOffset),
894894+ YOffset: uint32(yOffset),
895895+ SourceX: uint32(sourceX),
896896+ SourceY: uint32(sourceY),
897897+ SourceWidth: uint32(sourceWidth),
898898+ SourceHeight: uint32(sourceHeight),
899899+ Columns: uint32(columns),
900900+ Rows: uint32(rows),
901901+ Z: int32(z),
642902 }, nil
643903}
644904
+74
render_state_cell.go
···44// GhosttyRenderStateRowCells C APIs.
5566/*
77+#include <stdlib.h>
78#include <ghostty/vt.h>
89*/
910import "C"
···1314 "unsafe"
1415)
15161717+// RenderStateRowCellsData identifies a data field for render state cell
1818+// queries.
1919+// C: GhosttyRenderStateRowCellsData
2020+type RenderStateRowCellsData int
2121+2222+const (
2323+ // RenderStateRowCellsDataInvalid is an invalid / sentinel value.
2424+ RenderStateRowCellsDataInvalid RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_INVALID
2525+2626+ // RenderStateRowCellsDataRaw is the raw cell value (GhosttyCell).
2727+ RenderStateRowCellsDataRaw RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_RAW
2828+2929+ // RenderStateRowCellsDataStyle is the style for the current cell
3030+ // (GhosttyStyle).
3131+ RenderStateRowCellsDataStyle RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_STYLE
3232+3333+ // RenderStateRowCellsDataGraphemesLen is the total number of grapheme
3434+ // codepoints including the base codepoint (uint32_t).
3535+ RenderStateRowCellsDataGraphemesLen RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_GRAPHEMES_LEN
3636+3737+ // RenderStateRowCellsDataGraphemesBuf writes grapheme codepoints into
3838+ // a caller-provided buffer (uint32_t*).
3939+ RenderStateRowCellsDataGraphemesBuf RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_GRAPHEMES_BUF
4040+4141+ // RenderStateRowCellsDataBgColor is the resolved background color of
4242+ // the cell (GhosttyColorRgb).
4343+ RenderStateRowCellsDataBgColor RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_BG_COLOR
4444+4545+ // RenderStateRowCellsDataFgColor is the resolved foreground color of
4646+ // the cell (GhosttyColorRgb).
4747+ RenderStateRowCellsDataFgColor RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_FG_COLOR
4848+)
4949+1650// RenderStateRowCells iterates over cells in a render-state row.
1751// Create one with NewRenderStateRowCells, populate it via
1852// RenderStateRowIterator.Cells, then advance with Next (or jump
···5488// so that subsequent reads return data for that cell.
5589func (rc *RenderStateRowCells) Select(x uint16) error {
5690 return resultError(C.ghostty_render_state_row_cells_select(rc.ptr, C.uint16_t(x)))
9191+}
9292+9393+// GetMulti queries multiple render-state cell data fields in a single
9494+// cgo call. This is a low-level function; prefer the typed getters
9595+// (Raw, Style, Graphemes, BgColor, FgColor) for normal use. GetMulti
9696+// is useful when you need many fields at once and want to avoid
9797+// per-field cgo overhead.
9898+//
9999+// Each element in keys specifies a data kind, and the corresponding
100100+// element in values must be an unsafe.Pointer to a variable whose type
101101+// matches the "Output type" documented for that key in the upstream C
102102+// header (ghostty/vt/render.h, GhosttyRenderStateRowCellsData enum).
103103+//
104104+// Example:
105105+//
106106+// var raw C.GhosttyCell
107107+// var graphemesLen C.uint32_t
108108+// err := rc.GetMulti(
109109+// []RenderStateRowCellsData{RenderStateRowCellsDataRaw, RenderStateRowCellsDataGraphemesLen},
110110+// []unsafe.Pointer{unsafe.Pointer(&raw), unsafe.Pointer(&graphemesLen)},
111111+// )
112112+//
113113+// C: ghostty_render_state_row_cells_get_multi
114114+func (rc *RenderStateRowCells) GetMulti(keys []RenderStateRowCellsData, values []unsafe.Pointer) error {
115115+ if len(keys) != len(values) {
116116+ return errors.New("libghostty: keys and values must have the same length")
117117+ }
118118+ if len(keys) == 0 {
119119+ return nil
120120+ }
121121+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
122122+ cVals := cValuesArray(values)
123123+ defer C.free(unsafe.Pointer(cVals))
124124+ return resultError(C.ghostty_render_state_row_cells_get_multi(
125125+ rc.ptr,
126126+ C.size_t(len(keys)),
127127+ (*C.GhosttyRenderStateRowCellsData)(unsafe.Pointer(&keys[0])),
128128+ cVals,
129129+ nil,
130130+ ))
57131}
5813259133// Raw returns the raw Cell value for the current iterator position.
+114
render_state_data.go
···55// Functions are ordered alphabetically.
6677/*
88+#include <stdlib.h>
89#include <ghostty/vt.h>
9101011// Helper to create a properly initialized GhosttyRenderStateColors (sized struct).
···2021 "unsafe"
2122)
22232424+// RenderStateData identifies a data field for render state queries.
2525+// C: GhosttyRenderStateData
2626+type RenderStateData int
2727+2828+const (
2929+ // RenderStateDataInvalid is an invalid / sentinel value.
3030+ RenderStateDataInvalid RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_INVALID
3131+3232+ // RenderStateDataCols is the viewport width in cells (uint16_t).
3333+ RenderStateDataCols RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLS
3434+3535+ // RenderStateDataRows is the viewport height in cells (uint16_t).
3636+ RenderStateDataRows RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_ROWS
3737+3838+ // RenderStateDataDirty is the current dirty state
3939+ // (GhosttyRenderStateDirty).
4040+ RenderStateDataDirty RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_DIRTY
4141+4242+ // RenderStateDataRowIterator populates a pre-allocated row iterator
4343+ // (GhosttyRenderStateRowIterator).
4444+ RenderStateDataRowIterator RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_ROW_ITERATOR
4545+4646+ // RenderStateDataColorBackground is the default/current background
4747+ // color (GhosttyColorRgb).
4848+ RenderStateDataColorBackground RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_BACKGROUND
4949+5050+ // RenderStateDataColorForeground is the default/current foreground
5151+ // color (GhosttyColorRgb).
5252+ RenderStateDataColorForeground RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_FOREGROUND
5353+5454+ // RenderStateDataColorCursor is the cursor color when explicitly set
5555+ // (GhosttyColorRgb).
5656+ RenderStateDataColorCursor RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_CURSOR
5757+5858+ // RenderStateDataColorCursorHasValue indicates whether an explicit
5959+ // cursor color is set (bool).
6060+ RenderStateDataColorCursorHasValue RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_CURSOR_HAS_VALUE
6161+6262+ // RenderStateDataColorPalette is the active 256-color palette
6363+ // (GhosttyColorRgb[256]).
6464+ RenderStateDataColorPalette RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_PALETTE
6565+6666+ // RenderStateDataCursorVisualStyle is the visual style of the cursor
6767+ // (GhosttyRenderStateCursorVisualStyle).
6868+ RenderStateDataCursorVisualStyle RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VISUAL_STYLE
6969+7070+ // RenderStateDataCursorVisible indicates whether the cursor is visible
7171+ // based on terminal modes (bool).
7272+ RenderStateDataCursorVisible RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VISIBLE
7373+7474+ // RenderStateDataCursorBlinking indicates whether the cursor should
7575+ // blink based on terminal modes (bool).
7676+ RenderStateDataCursorBlinking RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_BLINKING
7777+7878+ // RenderStateDataCursorPasswordInput indicates whether the cursor is
7979+ // at a password input field (bool).
8080+ RenderStateDataCursorPasswordInput RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_PASSWORD_INPUT
8181+8282+ // RenderStateDataCursorViewportHasValue indicates whether the cursor
8383+ // is visible within the viewport (bool).
8484+ RenderStateDataCursorViewportHasValue RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_HAS_VALUE
8585+8686+ // RenderStateDataCursorViewportX is the cursor viewport x position
8787+ // in cells (uint16_t).
8888+ RenderStateDataCursorViewportX RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_X
8989+9090+ // RenderStateDataCursorViewportY is the cursor viewport y position
9191+ // in cells (uint16_t).
9292+ RenderStateDataCursorViewportY RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_Y
9393+9494+ // RenderStateDataCursorViewportWideTail indicates whether the cursor
9595+ // is on the tail of a wide character (bool).
9696+ RenderStateDataCursorViewportWideTail RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_WIDE_TAIL
9797+)
9898+2399// Cols returns the viewport width in cells.
24100func (rs *RenderState) Cols() (uint16, error) {
25101 var v C.uint16_t
···104180 result.Palette[i] = ColorRGB{R: uint8(c.r), G: uint8(c.g), B: uint8(c.b)}
105181 }
106182 return result, nil
183183+}
184184+185185+// GetMulti queries multiple render state data fields in a single cgo
186186+// call. This is a low-level function; prefer the typed getters (Cols,
187187+// Rows, CursorVisible, etc.) for normal use. GetMulti is useful when
188188+// you need many fields at once and want to avoid per-field cgo overhead.
189189+//
190190+// Each element in keys specifies a data kind, and the corresponding
191191+// element in values must be an unsafe.Pointer to a variable whose type
192192+// matches the "Output type" documented for that key in the upstream C
193193+// header (ghostty/vt/render.h, GhosttyRenderStateData enum).
194194+//
195195+// Example:
196196+//
197197+// var cols, rows C.uint16_t
198198+// err := rs.GetMulti(
199199+// []RenderStateData{RenderStateDataCols, RenderStateDataRows},
200200+// []unsafe.Pointer{unsafe.Pointer(&cols), unsafe.Pointer(&rows)},
201201+// )
202202+//
203203+// C: ghostty_render_state_get_multi
204204+func (rs *RenderState) GetMulti(keys []RenderStateData, values []unsafe.Pointer) error {
205205+ if len(keys) != len(values) {
206206+ return errors.New("libghostty: keys and values must have the same length")
207207+ }
208208+ if len(keys) == 0 {
209209+ return nil
210210+ }
211211+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
212212+ cVals := cValuesArray(values)
213213+ defer C.free(unsafe.Pointer(cVals))
214214+ return resultError(C.ghostty_render_state_get_multi(
215215+ rs.ptr,
216216+ C.size_t(len(keys)),
217217+ (*C.GhosttyRenderStateData)(unsafe.Pointer(&keys[0])),
218218+ cVals,
219219+ nil,
220220+ ))
107221}
108222109223// CursorBlinking reports whether the cursor should blink based on
+64-1
render_state_row.go
···44// GhosttyRenderStateRowIterator C APIs.
5566/*
77+#include <stdlib.h>
78#include <ghostty/vt.h>
89*/
910import "C"
10111111-import "unsafe"
1212+import (
1313+ "errors"
1414+ "unsafe"
1515+)
1616+1717+// RenderStateRowData identifies a data field for render state row queries.
1818+// C: GhosttyRenderStateRowData
1919+type RenderStateRowData int
2020+2121+const (
2222+ // RenderStateRowDataInvalid is an invalid / sentinel value.
2323+ RenderStateRowDataInvalid RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_INVALID
2424+2525+ // RenderStateRowDataDirty indicates whether the current row is dirty
2626+ // (bool).
2727+ RenderStateRowDataDirty RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_DIRTY
2828+2929+ // RenderStateRowDataRaw is the raw row value (GhosttyRow).
3030+ RenderStateRowDataRaw RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_RAW
3131+3232+ // RenderStateRowDataCells populates a pre-allocated row cells instance
3333+ // (GhosttyRenderStateRowCells).
3434+ RenderStateRowDataCells RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_CELLS
3535+)
12361337// RenderStateRowIterator iterates over rows in a render state.
1438// Create one with NewRenderStateRowIterator, populate it via
···4569// false when there are no more rows.
4670func (ri *RenderStateRowIterator) Next() bool {
4771 return bool(C.ghostty_render_state_row_iterator_next(ri.ptr))
7272+}
7373+7474+// GetMulti queries multiple render-state row data fields in a single
7575+// cgo call. This is a low-level function; prefer the typed getters
7676+// (Dirty, Raw, Cells) for normal use. GetMulti is useful when you
7777+// need many fields at once and want to avoid per-field cgo overhead.
7878+//
7979+// Each element in keys specifies a data kind, and the corresponding
8080+// element in values must be an unsafe.Pointer to a variable whose type
8181+// matches the "Output type" documented for that key in the upstream C
8282+// header (ghostty/vt/render.h, GhosttyRenderStateRowData enum).
8383+//
8484+// Example:
8585+//
8686+// var dirty C.bool
8787+// var raw C.GhosttyRow
8888+// err := ri.GetMulti(
8989+// []RenderStateRowData{RenderStateRowDataDirty, RenderStateRowDataRaw},
9090+// []unsafe.Pointer{unsafe.Pointer(&dirty), unsafe.Pointer(&raw)},
9191+// )
9292+//
9393+// C: ghostty_render_state_row_get_multi
9494+func (ri *RenderStateRowIterator) GetMulti(keys []RenderStateRowData, values []unsafe.Pointer) error {
9595+ if len(keys) != len(values) {
9696+ return errors.New("libghostty: keys and values must have the same length")
9797+ }
9898+ if len(keys) == 0 {
9999+ return nil
100100+ }
101101+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
102102+ cVals := cValuesArray(values)
103103+ defer C.free(unsafe.Pointer(cVals))
104104+ return resultError(C.ghostty_render_state_row_get_multi(
105105+ ri.ptr,
106106+ C.size_t(len(keys)),
107107+ (*C.GhosttyRenderStateRowData)(unsafe.Pointer(&keys[0])),
108108+ cVals,
109109+ nil,
110110+ ))
48111}
4911250113// Dirty reports whether the current row is dirty and requires a
+171-1
screen.go
···11package libghostty
2233/*
44+#include <stdlib.h>
45#include <ghostty/vt.h>
56*/
67import "C"
7888-import "unsafe"
99+import (
1010+ "errors"
1111+ "unsafe"
1212+)
1313+1414+// CellData identifies a data field for cell queries.
1515+// C: GhosttyCellData
1616+type CellData int
1717+1818+const (
1919+ // CellDataInvalid is an invalid data type.
2020+ CellDataInvalid CellData = C.GHOSTTY_CELL_DATA_INVALID
2121+2222+ // CellDataCodepoint is the codepoint of the cell (uint32_t).
2323+ CellDataCodepoint CellData = C.GHOSTTY_CELL_DATA_CODEPOINT
2424+2525+ // CellDataContentTag is the content tag describing what kind of
2626+ // content is in the cell (GhosttyCellContentTag).
2727+ CellDataContentTag CellData = C.GHOSTTY_CELL_DATA_CONTENT_TAG
2828+2929+ // CellDataWide is the wide property of the cell (GhosttyCellWide).
3030+ CellDataWide CellData = C.GHOSTTY_CELL_DATA_WIDE
3131+3232+ // CellDataHasText indicates whether the cell has text to render (bool).
3333+ CellDataHasText CellData = C.GHOSTTY_CELL_DATA_HAS_TEXT
3434+3535+ // CellDataHasStyling indicates whether the cell has non-default
3636+ // styling (bool).
3737+ CellDataHasStyling CellData = C.GHOSTTY_CELL_DATA_HAS_STYLING
3838+3939+ // CellDataStyleID is the style ID for the cell (uint16_t).
4040+ CellDataStyleID CellData = C.GHOSTTY_CELL_DATA_STYLE_ID
4141+4242+ // CellDataHasHyperlink indicates whether the cell has a hyperlink
4343+ // (bool).
4444+ CellDataHasHyperlink CellData = C.GHOSTTY_CELL_DATA_HAS_HYPERLINK
4545+4646+ // CellDataProtected indicates whether the cell is protected (bool).
4747+ CellDataProtected CellData = C.GHOSTTY_CELL_DATA_PROTECTED
4848+4949+ // CellDataSemanticContent is the semantic content type of the cell
5050+ // (GhosttyCellSemanticContent).
5151+ CellDataSemanticContent CellData = C.GHOSTTY_CELL_DATA_SEMANTIC_CONTENT
5252+5353+ // CellDataColorPalette is the palette index for the cell's background
5454+ // color (GhosttyColorPaletteIndex).
5555+ CellDataColorPalette CellData = C.GHOSTTY_CELL_DATA_COLOR_PALETTE
5656+5757+ // CellDataColorRGBValue is the RGB value for the cell's background
5858+ // color (GhosttyColorRgb).
5959+ CellDataColorRGBValue CellData = C.GHOSTTY_CELL_DATA_COLOR_RGB
6060+)
6161+6262+// RowData identifies a data field for row queries.
6363+// C: GhosttyRowData
6464+type RowData int
6565+6666+const (
6767+ // RowDataInvalid is an invalid data type.
6868+ RowDataInvalid RowData = C.GHOSTTY_ROW_DATA_INVALID
6969+7070+ // RowDataWrap indicates whether the row is soft-wrapped (bool).
7171+ RowDataWrap RowData = C.GHOSTTY_ROW_DATA_WRAP
7272+7373+ // RowDataWrapContinuation indicates whether the row is a continuation
7474+ // of a soft-wrapped row (bool).
7575+ RowDataWrapContinuation RowData = C.GHOSTTY_ROW_DATA_WRAP_CONTINUATION
7676+7777+ // RowDataGrapheme indicates whether any cells in the row have grapheme
7878+ // clusters (bool).
7979+ RowDataGrapheme RowData = C.GHOSTTY_ROW_DATA_GRAPHEME
8080+8181+ // RowDataStyled indicates whether any cells in the row have styling
8282+ // (bool).
8383+ RowDataStyled RowData = C.GHOSTTY_ROW_DATA_STYLED
8484+8585+ // RowDataHyperlink indicates whether any cells in the row have
8686+ // hyperlinks (bool).
8787+ RowDataHyperlink RowData = C.GHOSTTY_ROW_DATA_HYPERLINK
8888+8989+ // RowDataSemanticPrompt is the semantic prompt state of the row
9090+ // (GhosttyRowSemanticPrompt).
9191+ RowDataSemanticPrompt RowData = C.GHOSTTY_ROW_DATA_SEMANTIC_PROMPT
9292+9393+ // RowDataKittyVirtualPlaceholder indicates whether the row contains
9494+ // a Kitty virtual placeholder (bool).
9595+ RowDataKittyVirtualPlaceholder RowData = C.GHOSTTY_ROW_DATA_KITTY_VIRTUAL_PLACEHOLDER
9696+9797+ // RowDataDirty indicates whether the row is dirty and requires a
9898+ // redraw (bool).
9999+ RowDataDirty RowData = C.GHOSTTY_ROW_DATA_DIRTY
100100+)
910110102// Cell is a wrapper around an opaque terminal grid cell value.
11103// Use getter methods to extract data from it.
···93185 RowSemanticPromptContinuation RowSemanticPrompt = C.GHOSTTY_ROW_SEMANTIC_PROMPT_CONTINUATION
94186)
95187188188+// GetMulti queries multiple cell data fields in a single cgo call.
189189+// This is a low-level function; prefer the typed getters (Codepoint,
190190+// Wide, HasText, etc.) for normal use. GetMulti is useful when you
191191+// need many fields at once and want to avoid per-field cgo overhead.
192192+//
193193+// Each element in keys specifies a data kind, and the corresponding
194194+// element in values must be an unsafe.Pointer to a variable whose type
195195+// matches the "Output type" documented for that key in the upstream C
196196+// header (ghostty/vt/screen.h, GhosttyCellData enum).
197197+//
198198+// Example:
199199+//
200200+// var cp C.uint32_t
201201+// var wide C.GhosttyCellWide
202202+// err := cell.GetMulti(
203203+// []CellData{CellDataCodepoint, CellDataWide},
204204+// []unsafe.Pointer{unsafe.Pointer(&cp), unsafe.Pointer(&wide)},
205205+// )
206206+//
207207+// C: ghostty_cell_get_multi
208208+func (c *Cell) GetMulti(keys []CellData, values []unsafe.Pointer) error {
209209+ if len(keys) != len(values) {
210210+ return errors.New("libghostty: keys and values must have the same length")
211211+ }
212212+ if len(keys) == 0 {
213213+ return nil
214214+ }
215215+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
216216+ cVals := cValuesArray(values)
217217+ defer C.free(unsafe.Pointer(cVals))
218218+ return resultError(C.ghostty_cell_get_multi(
219219+ c.c,
220220+ C.size_t(len(keys)),
221221+ (*C.GhosttyCellData)(unsafe.Pointer(&keys[0])),
222222+ cVals,
223223+ nil,
224224+ ))
225225+}
226226+96227// Codepoint returns the codepoint of the cell (0 if empty).
97228func (c *Cell) Codepoint() (uint32, error) {
98229 var v C.uint32_t
···193324 return ColorRGB{}, err
194325 }
195326 return ColorRGB{R: uint8(v.r), G: uint8(v.g), B: uint8(v.b)}, nil
327327+}
328328+329329+// GetMulti queries multiple row data fields in a single cgo call.
330330+// This is a low-level function; prefer the typed getters (Wrap,
331331+// Grapheme, Styled, Semantic, etc.) for normal use. GetMulti is
332332+// useful when you need many fields at once and want to avoid
333333+// per-field cgo overhead.
334334+//
335335+// Each element in keys specifies a data kind, and the corresponding
336336+// element in values must be an unsafe.Pointer to a variable whose type
337337+// matches the "Output type" documented for that key in the upstream C
338338+// header (ghostty/vt/screen.h, GhosttyRowData enum).
339339+//
340340+// Example:
341341+//
342342+// var wrap, styled C.bool
343343+// err := row.GetMulti(
344344+// []RowData{RowDataWrap, RowDataStyled},
345345+// []unsafe.Pointer{unsafe.Pointer(&wrap), unsafe.Pointer(&styled)},
346346+// )
347347+//
348348+// C: ghostty_row_get_multi
349349+func (r *Row) GetMulti(keys []RowData, values []unsafe.Pointer) error {
350350+ if len(keys) != len(values) {
351351+ return errors.New("libghostty: keys and values must have the same length")
352352+ }
353353+ if len(keys) == 0 {
354354+ return nil
355355+ }
356356+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
357357+ cVals := cValuesArray(values)
358358+ defer C.free(unsafe.Pointer(cVals))
359359+ return resultError(C.ghostty_row_get_multi(
360360+ r.c,
361361+ C.size_t(len(keys)),
362362+ (*C.GhosttyRowData)(unsafe.Pointer(&keys[0])),
363363+ cVals,
364364+ nil,
365365+ ))
196366}
197367198368// Wrap reports whether the row is soft-wrapped.
+162
terminal_data.go
···44// Functions are ordered alphabetically.
5566/*
77+#include <stdlib.h>
78#include <ghostty/vt.h>
89*/
910import "C"
···1314 "unsafe"
1415)
15161717+// TerminalData identifies a data field for terminal queries.
1818+// C: GhosttyTerminalData
1919+type TerminalData int
2020+2121+const (
2222+ // TerminalDataInvalid is an invalid / sentinel value.
2323+ TerminalDataInvalid TerminalData = C.GHOSTTY_TERMINAL_DATA_INVALID
2424+2525+ // TerminalDataCols is the terminal width in cells (uint16_t).
2626+ TerminalDataCols TerminalData = C.GHOSTTY_TERMINAL_DATA_COLS
2727+2828+ // TerminalDataRows is the terminal height in cells (uint16_t).
2929+ TerminalDataRows TerminalData = C.GHOSTTY_TERMINAL_DATA_ROWS
3030+3131+ // TerminalDataCursorX is the cursor column position, 0-indexed (uint16_t).
3232+ TerminalDataCursorX TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_X
3333+3434+ // TerminalDataCursorY is the cursor row position within the active area,
3535+ // 0-indexed (uint16_t).
3636+ TerminalDataCursorY TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_Y
3737+3838+ // TerminalDataCursorPendingWrap indicates whether the cursor has a
3939+ // pending wrap (bool).
4040+ TerminalDataCursorPendingWrap TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_PENDING_WRAP
4141+4242+ // TerminalDataActiveScreen is the currently active screen
4343+ // (GhosttyTerminalScreen).
4444+ TerminalDataActiveScreen TerminalData = C.GHOSTTY_TERMINAL_DATA_ACTIVE_SCREEN
4545+4646+ // TerminalDataCursorVisible indicates whether the cursor is visible,
4747+ // DEC mode 25 (bool).
4848+ TerminalDataCursorVisible TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_VISIBLE
4949+5050+ // TerminalDataKittyKeyboardFlags is the current Kitty keyboard protocol
5151+ // flags (uint8_t).
5252+ TerminalDataKittyKeyboardFlags TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_KEYBOARD_FLAGS
5353+5454+ // TerminalDataScrollbar is the scrollbar state for the terminal viewport
5555+ // (GhosttyTerminalScrollbar).
5656+ TerminalDataScrollbar TerminalData = C.GHOSTTY_TERMINAL_DATA_SCROLLBAR
5757+5858+ // TerminalDataCursorStyle is the current SGR style of the cursor
5959+ // (GhosttyStyle).
6060+ TerminalDataCursorStyle TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_STYLE
6161+6262+ // TerminalDataMouseTracking indicates whether any mouse tracking mode
6363+ // is active (bool).
6464+ TerminalDataMouseTracking TerminalData = C.GHOSTTY_TERMINAL_DATA_MOUSE_TRACKING
6565+6666+ // TerminalDataTitle is the terminal title as set by escape sequences
6767+ // (GhosttyString).
6868+ TerminalDataTitle TerminalData = C.GHOSTTY_TERMINAL_DATA_TITLE
6969+7070+ // TerminalDataPwd is the terminal's current working directory as set
7171+ // by escape sequences (GhosttyString).
7272+ TerminalDataPwd TerminalData = C.GHOSTTY_TERMINAL_DATA_PWD
7373+7474+ // TerminalDataTotalRows is the total number of rows in the active screen
7575+ // including scrollback (size_t).
7676+ TerminalDataTotalRows TerminalData = C.GHOSTTY_TERMINAL_DATA_TOTAL_ROWS
7777+7878+ // TerminalDataScrollbackRows is the number of scrollback rows (size_t).
7979+ TerminalDataScrollbackRows TerminalData = C.GHOSTTY_TERMINAL_DATA_SCROLLBACK_ROWS
8080+8181+ // TerminalDataWidthPx is the total terminal width in pixels (uint32_t).
8282+ TerminalDataWidthPx TerminalData = C.GHOSTTY_TERMINAL_DATA_WIDTH_PX
8383+8484+ // TerminalDataHeightPx is the total terminal height in pixels (uint32_t).
8585+ TerminalDataHeightPx TerminalData = C.GHOSTTY_TERMINAL_DATA_HEIGHT_PX
8686+8787+ // TerminalDataColorForeground is the effective foreground color
8888+ // (GhosttyColorRgb).
8989+ TerminalDataColorForeground TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND
9090+9191+ // TerminalDataColorBackground is the effective background color
9292+ // (GhosttyColorRgb).
9393+ TerminalDataColorBackground TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND
9494+9595+ // TerminalDataColorCursor is the effective cursor color
9696+ // (GhosttyColorRgb).
9797+ TerminalDataColorCursor TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_CURSOR
9898+9999+ // TerminalDataColorPalette is the current 256-color palette
100100+ // (GhosttyColorRgb[256]).
101101+ TerminalDataColorPalette TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_PALETTE
102102+103103+ // TerminalDataColorForegroundDefault is the default foreground color,
104104+ // ignoring OSC overrides (GhosttyColorRgb).
105105+ TerminalDataColorForegroundDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND_DEFAULT
106106+107107+ // TerminalDataColorBackgroundDefault is the default background color,
108108+ // ignoring OSC overrides (GhosttyColorRgb).
109109+ TerminalDataColorBackgroundDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND_DEFAULT
110110+111111+ // TerminalDataColorCursorDefault is the default cursor color,
112112+ // ignoring OSC overrides (GhosttyColorRgb).
113113+ TerminalDataColorCursorDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_CURSOR_DEFAULT
114114+115115+ // TerminalDataColorPaletteDefault is the default 256-color palette,
116116+ // ignoring OSC overrides (GhosttyColorRgb[256]).
117117+ TerminalDataColorPaletteDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_PALETTE_DEFAULT
118118+119119+ // TerminalDataKittyImageStorageLimit is the Kitty image storage limit
120120+ // in bytes for the active screen (uint64_t).
121121+ TerminalDataKittyImageStorageLimit TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_STORAGE_LIMIT
122122+123123+ // TerminalDataKittyImageMediumFile indicates whether the file medium
124124+ // is enabled for Kitty image loading (bool).
125125+ TerminalDataKittyImageMediumFile TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_FILE
126126+127127+ // TerminalDataKittyImageMediumTempFile indicates whether the temporary
128128+ // file medium is enabled for Kitty image loading (bool).
129129+ TerminalDataKittyImageMediumTempFile TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_TEMP_FILE
130130+131131+ // TerminalDataKittyImageMediumSharedMem indicates whether the shared
132132+ // memory medium is enabled for Kitty image loading (bool).
133133+ TerminalDataKittyImageMediumSharedMem TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_SHARED_MEM
134134+135135+ // TerminalDataKittyGraphics is the Kitty graphics image storage for
136136+ // the active screen (GhosttyKittyGraphics).
137137+ TerminalDataKittyGraphics TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS
138138+)
139139+16140// ActiveScreen returns which screen buffer is currently active.
17141func (t *Terminal) ActiveScreen() (TerminalScreen, error) {
18142 var v C.GhosttyTerminalScreen
···77201// any OSC overrides.
78202func (t *Terminal) ColorPaletteDefault() (*Palette, error) {
79203 return t.getPalette(C.GHOSTTY_TERMINAL_DATA_COLOR_PALETTE_DEFAULT)
204204+}
205205+206206+// GetMulti queries multiple terminal data fields in a single cgo call.
207207+// This is a low-level function; prefer the typed getters (Cols, Rows,
208208+// CursorX, etc.) for normal use. GetMulti is useful when you need many
209209+// fields at once and want to avoid per-field cgo overhead.
210210+//
211211+// Each element in keys specifies a data kind, and the corresponding
212212+// element in values must be an unsafe.Pointer to a variable whose type
213213+// matches the "Output type" documented for that key in the upstream C
214214+// header (ghostty/vt/terminal.h, GhosttyTerminalData enum).
215215+//
216216+// Example:
217217+//
218218+// var cols, rows C.uint16_t
219219+// err := t.GetMulti(
220220+// []TerminalData{TerminalDataCols, TerminalDataRows},
221221+// []unsafe.Pointer{unsafe.Pointer(&cols), unsafe.Pointer(&rows)},
222222+// )
223223+//
224224+// C: ghostty_terminal_get_multi
225225+func (t *Terminal) GetMulti(keys []TerminalData, values []unsafe.Pointer) error {
226226+ if len(keys) != len(values) {
227227+ return errors.New("libghostty: keys and values must have the same length")
228228+ }
229229+ if len(keys) == 0 {
230230+ return nil
231231+ }
232232+ // Allocate the void** array in C memory to satisfy cgo pointer-passing rules.
233233+ cVals := cValuesArray(values)
234234+ defer C.free(unsafe.Pointer(cVals))
235235+ return resultError(C.ghostty_terminal_get_multi(
236236+ t.ptr,
237237+ C.size_t(len(keys)),
238238+ (*C.GhosttyTerminalData)(unsafe.Pointer(&keys[0])),
239239+ cVals,
240240+ nil,
241241+ ))
80242}
8124382244// CursorPendingWrap reports whether the cursor has a pending wrap