Go bindings for libghostty-vt.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

bind upstream get_multi APIs, replace sized-struct Info()

Update the pinned ghostty commit to pick up the new _get_multi C
APIs added across all getter types (terminal, render state, row,
cell, screen, kitty graphics image, kitty graphics placement).

The existing Info() methods on KittyGraphicsImage and
KittyGraphicsPlacementIterator previously used sized-struct C
types (GhosttyKittyGraphicsImageInfo, etc.) initialized via
GHOSTTY_INIT_SIZED. These are replaced by get_multi calls that
fetch each field individually through typed pointers, eliminating
struct ABI concerns (padding, alignment, field ordering) at the
cgo boundary. The Go-side convenience structs remain unchanged.

Each type also gains a public GetMulti method that exposes the
raw get_multi API for callers who want to batch arbitrary subsets
of queries into a single cgo crossing.

A shared cValuesArray helper in get_multi.go solves the cgo
pointer-passing rule for void**: the array of output pointers is
allocated in C heap memory, populated from Go, passed to C, then
freed.

+922 -54
+1 -1
CMakeLists.txt
··· 4 4 include(FetchContent) 5 5 FetchContent_Declare(ghostty 6 6 GIT_REPOSITORY https://github.com/ghostty-org/ghostty.git 7 - GIT_TAG 7421b4b13f87e101d4bbcedd4da84886ceae4e7b 7 + GIT_TAG c36b458ad57a95869745e405c9d8d45104a97773 8 8 ) 9 9 FetchContent_MakeAvailable(ghostty)
+25
get_multi.go
··· 1 + package libghostty 2 + 3 + // Shared helpers for the get_multi pattern used by multiple types. 4 + // These helpers solve the cgo pointer-passing rule: Go cannot pass 5 + // a Go-allocated void** (array of pointers to Go memory) directly 6 + // to C. Instead, we allocate the void** array in C heap memory, 7 + // copy the Go pointer values in, call the C function, then free. 8 + 9 + /* 10 + #include <stdlib.h> 11 + */ 12 + import "C" 13 + 14 + import "unsafe" 15 + 16 + // cValuesArray allocates a C-heap array of void* pointers, copies the 17 + // Go unsafe.Pointer values into it, and returns the C array pointer. 18 + // The caller must free the returned pointer with C.free when done. 19 + func cValuesArray(values []unsafe.Pointer) *unsafe.Pointer { 20 + n := len(values) 21 + cArr := (*unsafe.Pointer)(C.malloc(C.size_t(n) * C.size_t(unsafe.Sizeof(unsafe.Pointer(nil))))) 22 + dst := unsafe.Slice(cArr, n) 23 + copy(dst, values) 24 + return cArr 25 + }
+311 -51
kitty_graphics.go
··· 5 5 // protocol. 6 6 7 7 /* 8 + #include <stdlib.h> 8 9 #include <ghostty/vt.h> 9 10 10 11 // Helper to create a properly initialized GhosttySelection (sized struct). ··· 13 14 return s; 14 15 } 15 16 16 - // Helper to create a properly initialized GhosttyKittyGraphicsImageInfo (sized struct). 17 - static inline GhosttyKittyGraphicsImageInfo init_kitty_image_info() { 18 - GhosttyKittyGraphicsImageInfo info = GHOSTTY_INIT_SIZED(GhosttyKittyGraphicsImageInfo); 19 - return info; 20 - } 21 - 22 - // Helper to create a properly initialized GhosttyKittyGraphicsPlacementInfo (sized struct). 23 - static inline GhosttyKittyGraphicsPlacementInfo init_kitty_placement_info() { 24 - GhosttyKittyGraphicsPlacementInfo info = GHOSTTY_INIT_SIZED(GhosttyKittyGraphicsPlacementInfo); 25 - return info; 26 - } 27 - 28 17 // Helper to create a properly initialized GhosttyKittyGraphicsPlacementRenderInfo (sized struct). 29 18 static inline GhosttyKittyGraphicsPlacementRenderInfo init_kitty_placement_render_info() { 30 19 GhosttyKittyGraphicsPlacementRenderInfo info = GHOSTTY_INIT_SIZED(GhosttyKittyGraphicsPlacementRenderInfo); ··· 33 22 */ 34 23 import "C" 35 24 36 - import "unsafe" 25 + import ( 26 + "errors" 27 + "unsafe" 28 + ) 29 + 30 + // KittyGraphicsImageData identifies a data field for Kitty graphics 31 + // image queries. 32 + // C: GhosttyKittyGraphicsImageData 33 + type KittyGraphicsImageData int 34 + 35 + const ( 36 + // KittyGraphicsImageDataInvalid is an invalid / sentinel value. 37 + KittyGraphicsImageDataInvalid KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_INVALID 38 + 39 + // KittyGraphicsImageDataID is the image ID (uint32_t). 40 + KittyGraphicsImageDataID KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_ID 41 + 42 + // KittyGraphicsImageDataNumber is the image number (uint32_t). 43 + KittyGraphicsImageDataNumber KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_NUMBER 44 + 45 + // KittyGraphicsImageDataWidth is the image width in pixels (uint32_t). 46 + KittyGraphicsImageDataWidth KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_WIDTH 47 + 48 + // KittyGraphicsImageDataHeight is the image height in pixels (uint32_t). 49 + KittyGraphicsImageDataHeight KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_HEIGHT 50 + 51 + // KittyGraphicsImageDataFormat is the pixel format of the image 52 + // (GhosttyKittyImageFormat). 53 + KittyGraphicsImageDataFormat KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_FORMAT 54 + 55 + // KittyGraphicsImageDataCompression is the compression of the image 56 + // (GhosttyKittyImageCompression). 57 + KittyGraphicsImageDataCompression KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_COMPRESSION 58 + 59 + // KittyGraphicsImageDataDataPtr is a borrowed pointer to the raw pixel 60 + // data (const uint8_t **). 61 + KittyGraphicsImageDataDataPtr KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR 62 + 63 + // KittyGraphicsImageDataDataLen is the length of the raw pixel data 64 + // in bytes (size_t). 65 + KittyGraphicsImageDataDataLen KittyGraphicsImageData = C.GHOSTTY_KITTY_IMAGE_DATA_DATA_LEN 66 + ) 67 + 68 + // KittyGraphicsPlacementData identifies a data field for Kitty graphics 69 + // placement queries. 70 + // C: GhosttyKittyGraphicsPlacementData 71 + type KittyGraphicsPlacementData int 72 + 73 + const ( 74 + // KittyGraphicsPlacementDataInvalid is an invalid / sentinel value. 75 + KittyGraphicsPlacementDataInvalid KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INVALID 76 + 77 + // KittyGraphicsPlacementDataImageID is the image ID this placement 78 + // belongs to (uint32_t). 79 + KittyGraphicsPlacementDataImageID KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID 80 + 81 + // KittyGraphicsPlacementDataPlacementID is the placement ID (uint32_t). 82 + KittyGraphicsPlacementDataPlacementID KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID 83 + 84 + // KittyGraphicsPlacementDataIsVirtual indicates whether this is a 85 + // virtual placement (bool). 86 + KittyGraphicsPlacementDataIsVirtual KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL 87 + 88 + // KittyGraphicsPlacementDataXOffset is the pixel offset from the left 89 + // edge of the cell (uint32_t). 90 + KittyGraphicsPlacementDataXOffset KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET 91 + 92 + // KittyGraphicsPlacementDataYOffset is the pixel offset from the top 93 + // edge of the cell (uint32_t). 94 + KittyGraphicsPlacementDataYOffset KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET 95 + 96 + // KittyGraphicsPlacementDataSourceX is the source rectangle x origin 97 + // in pixels (uint32_t). 98 + KittyGraphicsPlacementDataSourceX KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X 99 + 100 + // KittyGraphicsPlacementDataSourceY is the source rectangle y origin 101 + // in pixels (uint32_t). 102 + KittyGraphicsPlacementDataSourceY KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y 103 + 104 + // KittyGraphicsPlacementDataSourceWidth is the source rectangle width 105 + // in pixels (uint32_t). 106 + KittyGraphicsPlacementDataSourceWidth KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH 107 + 108 + // KittyGraphicsPlacementDataSourceHeight is the source rectangle height 109 + // in pixels (uint32_t). 110 + KittyGraphicsPlacementDataSourceHeight KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT 111 + 112 + // KittyGraphicsPlacementDataColumns is the number of columns this 113 + // placement occupies (uint32_t). 114 + KittyGraphicsPlacementDataColumns KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS 115 + 116 + // KittyGraphicsPlacementDataRows is the number of rows this placement 117 + // occupies (uint32_t). 118 + KittyGraphicsPlacementDataRows KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS 119 + 120 + // KittyGraphicsPlacementDataZ is the z-index for this placement 121 + // (int32_t). 122 + KittyGraphicsPlacementDataZ KittyGraphicsPlacementData = C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z 123 + ) 37 124 38 125 // KittyGraphics is a handle to the Kitty graphics image storage 39 126 // associated with a terminal's active screen. It is borrowed from ··· 146 233 } 147 234 148 235 // KittyGraphicsImageInfo contains all image metadata in a single struct. 149 - // This is more efficient than querying each field individually since it 150 - // requires only one cgo call. 151 - // 152 - // C: GhosttyKittyGraphicsImageInfo 236 + // This is a Go-only convenience type; it has no corresponding C struct. 237 + // Populated via get_multi in a single cgo call. 153 238 type KittyGraphicsImageInfo struct { 154 239 // ID is the image ID. 155 240 ID uint32 ··· 175 260 } 176 261 177 262 // KittyGraphicsPlacementInfo contains all placement metadata in a single 178 - // struct. This is more efficient than querying each field individually 179 - // since it requires only one cgo call. 180 - // 181 - // C: GhosttyKittyGraphicsPlacementInfo 263 + // struct. This is a Go-only convenience type; it has no corresponding 264 + // C struct. Populated via get_multi in a single cgo call. 182 265 type KittyGraphicsPlacementInfo struct { 183 266 // ImageID is the image ID this placement belongs to. 184 267 ImageID uint32 ··· 334 417 return uint32(v), nil 335 418 } 336 419 420 + // GetMulti queries multiple image data fields in a single cgo call. 421 + // This is a low-level function; prefer the typed getters (ID, Width, 422 + // Height, Format, etc.) or Info() for normal use. GetMulti is useful 423 + // when you need a custom subset of fields and want to avoid per-field 424 + // cgo overhead. 425 + // 426 + // Each element in keys specifies a data kind, and the corresponding 427 + // element in values must be an unsafe.Pointer to a variable whose type 428 + // matches the "Output type" documented for that key in the upstream C 429 + // header (ghostty/vt/kitty_graphics.h, GhosttyKittyGraphicsImageData 430 + // enum). 431 + // 432 + // Example: 433 + // 434 + // var w, h C.uint32_t 435 + // err := img.GetMulti( 436 + // []KittyGraphicsImageData{KittyGraphicsImageDataWidth, KittyGraphicsImageDataHeight}, 437 + // []unsafe.Pointer{unsafe.Pointer(&w), unsafe.Pointer(&h)}, 438 + // ) 439 + // 440 + // C: ghostty_kitty_graphics_image_get_multi 441 + func (img *KittyGraphicsImage) GetMulti(keys []KittyGraphicsImageData, values []unsafe.Pointer) error { 442 + if len(keys) != len(values) { 443 + return errors.New("libghostty: keys and values must have the same length") 444 + } 445 + if len(keys) == 0 { 446 + return nil 447 + } 448 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 449 + cVals := cValuesArray(values) 450 + defer C.free(unsafe.Pointer(cVals)) 451 + return resultError(C.ghostty_kitty_graphics_image_get_multi( 452 + img.ptr, 453 + C.size_t(len(keys)), 454 + (*C.GhosttyKittyGraphicsImageData)(unsafe.Pointer(&keys[0])), 455 + cVals, 456 + nil, 457 + )) 458 + } 459 + 337 460 // Format returns the pixel format of the image. 338 461 func (img *KittyGraphicsImage) Format() (KittyImageFormat, error) { 339 462 var v C.GhosttyKittyImageFormat ··· 362 485 363 486 // Info returns all image metadata in a single call. This is more 364 487 // efficient than calling ID, Number, Width, Height, Format, 365 - // Compression, and Data individually. 488 + // Compression, and Data individually. Uses the get_multi C API 489 + // to fetch all fields in one cgo round-trip. 366 490 func (img *KittyGraphicsImage) Info() (*KittyGraphicsImageInfo, error) { 367 - ci := C.init_kitty_image_info() 368 - if err := resultError(C.ghostty_kitty_graphics_image_get( 491 + // Output variables — one per field, typed to match the C API. 492 + var ( 493 + id C.uint32_t 494 + number C.uint32_t 495 + width C.uint32_t 496 + height C.uint32_t 497 + format C.GhosttyKittyImageFormat 498 + compression C.GhosttyKittyImageCompression 499 + dataPtr *C.uint8_t 500 + dataLen C.size_t 501 + ) 502 + 503 + // Keys identify which fields to fetch; order must match values. 504 + keys := [...]C.GhosttyKittyGraphicsImageData{ 505 + C.GHOSTTY_KITTY_IMAGE_DATA_ID, 506 + C.GHOSTTY_KITTY_IMAGE_DATA_NUMBER, 507 + C.GHOSTTY_KITTY_IMAGE_DATA_WIDTH, 508 + C.GHOSTTY_KITTY_IMAGE_DATA_HEIGHT, 509 + C.GHOSTTY_KITTY_IMAGE_DATA_FORMAT, 510 + C.GHOSTTY_KITTY_IMAGE_DATA_COMPRESSION, 511 + C.GHOSTTY_KITTY_IMAGE_DATA_DATA_PTR, 512 + C.GHOSTTY_KITTY_IMAGE_DATA_DATA_LEN, 513 + } 514 + 515 + // Each value pointer receives the corresponding field from C. 516 + // We must allocate the void** array in C memory to satisfy cgo 517 + // pointer-passing rules (Go cannot pass a Go pointer containing 518 + // other Go pointers to C). 519 + values := [...]unsafe.Pointer{ 520 + unsafe.Pointer(&id), 521 + unsafe.Pointer(&number), 522 + unsafe.Pointer(&width), 523 + unsafe.Pointer(&height), 524 + unsafe.Pointer(&format), 525 + unsafe.Pointer(&compression), 526 + unsafe.Pointer(&dataPtr), 527 + unsafe.Pointer(&dataLen), 528 + } 529 + cVals := cValuesArray(values[:]) 530 + defer C.free(unsafe.Pointer(cVals)) 531 + 532 + if err := resultError(C.ghostty_kitty_graphics_image_get_multi( 369 533 img.ptr, 370 - C.GHOSTTY_KITTY_IMAGE_DATA_INFO, 371 - unsafe.Pointer(&ci), 534 + C.size_t(len(keys)), 535 + &keys[0], 536 + cVals, 537 + nil, 372 538 )); err != nil { 373 539 return nil, err 374 540 } 375 541 376 542 info := &KittyGraphicsImageInfo{ 377 - ID: uint32(ci.id), 378 - Number: uint32(ci.number), 379 - Width: uint32(ci.width), 380 - Height: uint32(ci.height), 381 - Format: KittyImageFormat(ci.format), 382 - Compression: KittyImageCompression(ci.compression), 543 + ID: uint32(id), 544 + Number: uint32(number), 545 + Width: uint32(width), 546 + Height: uint32(height), 547 + Format: KittyImageFormat(format), 548 + Compression: KittyImageCompression(compression), 383 549 } 384 550 385 - if ci.data_ptr != nil && ci.data_len > 0 { 386 - info.Data = unsafe.Slice((*byte)(unsafe.Pointer(ci.data_ptr)), int(ci.data_len)) 551 + if dataPtr != nil && dataLen > 0 { 552 + info.Data = unsafe.Slice((*byte)(unsafe.Pointer(dataPtr)), int(dataLen)) 387 553 } 388 554 389 555 return info, nil ··· 453 619 return bool(C.ghostty_kitty_graphics_placement_next(it.ptr)) 454 620 } 455 621 622 + // GetMulti queries multiple placement data fields in a single cgo 623 + // call. This is a low-level function; prefer the typed getters 624 + // (ImageID, PlacementID, Z, etc.) or Info() for normal use. GetMulti 625 + // is useful when you need a custom subset of fields and want to avoid 626 + // per-field cgo overhead. 627 + // 628 + // Each element in keys specifies a data kind, and the corresponding 629 + // element in values must be an unsafe.Pointer to a variable whose type 630 + // matches the "Output type" documented for that key in the upstream C 631 + // header (ghostty/vt/kitty_graphics.h, 632 + // GhosttyKittyGraphicsPlacementData enum). 633 + // 634 + // Example: 635 + // 636 + // var imageID C.uint32_t 637 + // var z C.int32_t 638 + // err := it.GetMulti( 639 + // []KittyGraphicsPlacementData{KittyGraphicsPlacementDataImageID, KittyGraphicsPlacementDataZ}, 640 + // []unsafe.Pointer{unsafe.Pointer(&imageID), unsafe.Pointer(&z)}, 641 + // ) 642 + // 643 + // C: ghostty_kitty_graphics_placement_get_multi 644 + func (it *KittyGraphicsPlacementIterator) GetMulti(keys []KittyGraphicsPlacementData, values []unsafe.Pointer) error { 645 + if len(keys) != len(values) { 646 + return errors.New("libghostty: keys and values must have the same length") 647 + } 648 + if len(keys) == 0 { 649 + return nil 650 + } 651 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 652 + cVals := cValuesArray(values) 653 + defer C.free(unsafe.Pointer(cVals)) 654 + return resultError(C.ghostty_kitty_graphics_placement_get_multi( 655 + it.ptr, 656 + C.size_t(len(keys)), 657 + (*C.GhosttyKittyGraphicsPlacementData)(unsafe.Pointer(&keys[0])), 658 + cVals, 659 + nil, 660 + )) 661 + } 662 + 456 663 // ImageID returns the image ID of the current placement. 457 664 func (it *KittyGraphicsPlacementIterator) ImageID() (uint32, error) { 458 665 var v C.uint32_t ··· 615 822 // Info returns all placement metadata in a single call. This is more 616 823 // efficient than calling ImageID, PlacementID, IsVirtual, XOffset, 617 824 // YOffset, SourceX, SourceY, SourceWidth, SourceHeight, Columns, 618 - // Rows, and Z individually. 825 + // Rows, and Z individually. Uses the get_multi C API to fetch all 826 + // fields in one cgo round-trip. 619 827 func (it *KittyGraphicsPlacementIterator) Info() (*KittyGraphicsPlacementInfo, error) { 620 - ci := C.init_kitty_placement_info() 621 - if err := resultError(C.ghostty_kitty_graphics_placement_get( 828 + // Output variables — one per field, typed to match the C API. 829 + var ( 830 + imageID C.uint32_t 831 + placementID C.uint32_t 832 + isVirtual C.bool 833 + xOffset C.uint32_t 834 + yOffset C.uint32_t 835 + sourceX C.uint32_t 836 + sourceY C.uint32_t 837 + sourceWidth C.uint32_t 838 + sourceHeight C.uint32_t 839 + columns C.uint32_t 840 + rows C.uint32_t 841 + z C.int32_t 842 + ) 843 + 844 + // Keys identify which fields to fetch; order must match values. 845 + keys := [...]C.GhosttyKittyGraphicsPlacementData{ 846 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID, 847 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID, 848 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL, 849 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET, 850 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET, 851 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X, 852 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y, 853 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH, 854 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT, 855 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS, 856 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS, 857 + C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z, 858 + } 859 + 860 + // Each value pointer receives the corresponding field from C. 861 + // Allocated in C memory to satisfy cgo pointer-passing rules. 862 + values := [...]unsafe.Pointer{ 863 + unsafe.Pointer(&imageID), 864 + unsafe.Pointer(&placementID), 865 + unsafe.Pointer(&isVirtual), 866 + unsafe.Pointer(&xOffset), 867 + unsafe.Pointer(&yOffset), 868 + unsafe.Pointer(&sourceX), 869 + unsafe.Pointer(&sourceY), 870 + unsafe.Pointer(&sourceWidth), 871 + unsafe.Pointer(&sourceHeight), 872 + unsafe.Pointer(&columns), 873 + unsafe.Pointer(&rows), 874 + unsafe.Pointer(&z), 875 + } 876 + cVals := cValuesArray(values[:]) 877 + defer C.free(unsafe.Pointer(cVals)) 878 + 879 + if err := resultError(C.ghostty_kitty_graphics_placement_get_multi( 622 880 it.ptr, 623 - C.GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INFO, 624 - unsafe.Pointer(&ci), 881 + C.size_t(len(keys)), 882 + &keys[0], 883 + cVals, 884 + nil, 625 885 )); err != nil { 626 886 return nil, err 627 887 } 628 888 629 889 return &KittyGraphicsPlacementInfo{ 630 - ImageID: uint32(ci.image_id), 631 - PlacementID: uint32(ci.placement_id), 632 - IsVirtual: bool(ci.is_virtual), 633 - XOffset: uint32(ci.x_offset), 634 - YOffset: uint32(ci.y_offset), 635 - SourceX: uint32(ci.source_x), 636 - SourceY: uint32(ci.source_y), 637 - SourceWidth: uint32(ci.source_width), 638 - SourceHeight: uint32(ci.source_height), 639 - Columns: uint32(ci.columns), 640 - Rows: uint32(ci.rows), 641 - Z: int32(ci.z), 890 + ImageID: uint32(imageID), 891 + PlacementID: uint32(placementID), 892 + IsVirtual: bool(isVirtual), 893 + XOffset: uint32(xOffset), 894 + YOffset: uint32(yOffset), 895 + SourceX: uint32(sourceX), 896 + SourceY: uint32(sourceY), 897 + SourceWidth: uint32(sourceWidth), 898 + SourceHeight: uint32(sourceHeight), 899 + Columns: uint32(columns), 900 + Rows: uint32(rows), 901 + Z: int32(z), 642 902 }, nil 643 903 } 644 904
+74
render_state_cell.go
··· 4 4 // GhosttyRenderStateRowCells C APIs. 5 5 6 6 /* 7 + #include <stdlib.h> 7 8 #include <ghostty/vt.h> 8 9 */ 9 10 import "C" ··· 13 14 "unsafe" 14 15 ) 15 16 17 + // RenderStateRowCellsData identifies a data field for render state cell 18 + // queries. 19 + // C: GhosttyRenderStateRowCellsData 20 + type RenderStateRowCellsData int 21 + 22 + const ( 23 + // RenderStateRowCellsDataInvalid is an invalid / sentinel value. 24 + RenderStateRowCellsDataInvalid RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_INVALID 25 + 26 + // RenderStateRowCellsDataRaw is the raw cell value (GhosttyCell). 27 + RenderStateRowCellsDataRaw RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_RAW 28 + 29 + // RenderStateRowCellsDataStyle is the style for the current cell 30 + // (GhosttyStyle). 31 + RenderStateRowCellsDataStyle RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_STYLE 32 + 33 + // RenderStateRowCellsDataGraphemesLen is the total number of grapheme 34 + // codepoints including the base codepoint (uint32_t). 35 + RenderStateRowCellsDataGraphemesLen RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_GRAPHEMES_LEN 36 + 37 + // RenderStateRowCellsDataGraphemesBuf writes grapheme codepoints into 38 + // a caller-provided buffer (uint32_t*). 39 + RenderStateRowCellsDataGraphemesBuf RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_GRAPHEMES_BUF 40 + 41 + // RenderStateRowCellsDataBgColor is the resolved background color of 42 + // the cell (GhosttyColorRgb). 43 + RenderStateRowCellsDataBgColor RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_BG_COLOR 44 + 45 + // RenderStateRowCellsDataFgColor is the resolved foreground color of 46 + // the cell (GhosttyColorRgb). 47 + RenderStateRowCellsDataFgColor RenderStateRowCellsData = C.GHOSTTY_RENDER_STATE_ROW_CELLS_DATA_FG_COLOR 48 + ) 49 + 16 50 // RenderStateRowCells iterates over cells in a render-state row. 17 51 // Create one with NewRenderStateRowCells, populate it via 18 52 // RenderStateRowIterator.Cells, then advance with Next (or jump ··· 54 88 // so that subsequent reads return data for that cell. 55 89 func (rc *RenderStateRowCells) Select(x uint16) error { 56 90 return resultError(C.ghostty_render_state_row_cells_select(rc.ptr, C.uint16_t(x))) 91 + } 92 + 93 + // GetMulti queries multiple render-state cell data fields in a single 94 + // cgo call. This is a low-level function; prefer the typed getters 95 + // (Raw, Style, Graphemes, BgColor, FgColor) for normal use. GetMulti 96 + // is useful when you need many fields at once and want to avoid 97 + // per-field cgo overhead. 98 + // 99 + // Each element in keys specifies a data kind, and the corresponding 100 + // element in values must be an unsafe.Pointer to a variable whose type 101 + // matches the "Output type" documented for that key in the upstream C 102 + // header (ghostty/vt/render.h, GhosttyRenderStateRowCellsData enum). 103 + // 104 + // Example: 105 + // 106 + // var raw C.GhosttyCell 107 + // var graphemesLen C.uint32_t 108 + // err := rc.GetMulti( 109 + // []RenderStateRowCellsData{RenderStateRowCellsDataRaw, RenderStateRowCellsDataGraphemesLen}, 110 + // []unsafe.Pointer{unsafe.Pointer(&raw), unsafe.Pointer(&graphemesLen)}, 111 + // ) 112 + // 113 + // C: ghostty_render_state_row_cells_get_multi 114 + func (rc *RenderStateRowCells) GetMulti(keys []RenderStateRowCellsData, values []unsafe.Pointer) error { 115 + if len(keys) != len(values) { 116 + return errors.New("libghostty: keys and values must have the same length") 117 + } 118 + if len(keys) == 0 { 119 + return nil 120 + } 121 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 122 + cVals := cValuesArray(values) 123 + defer C.free(unsafe.Pointer(cVals)) 124 + return resultError(C.ghostty_render_state_row_cells_get_multi( 125 + rc.ptr, 126 + C.size_t(len(keys)), 127 + (*C.GhosttyRenderStateRowCellsData)(unsafe.Pointer(&keys[0])), 128 + cVals, 129 + nil, 130 + )) 57 131 } 58 132 59 133 // Raw returns the raw Cell value for the current iterator position.
+114
render_state_data.go
··· 5 5 // Functions are ordered alphabetically. 6 6 7 7 /* 8 + #include <stdlib.h> 8 9 #include <ghostty/vt.h> 9 10 10 11 // Helper to create a properly initialized GhosttyRenderStateColors (sized struct). ··· 20 21 "unsafe" 21 22 ) 22 23 24 + // RenderStateData identifies a data field for render state queries. 25 + // C: GhosttyRenderStateData 26 + type RenderStateData int 27 + 28 + const ( 29 + // RenderStateDataInvalid is an invalid / sentinel value. 30 + RenderStateDataInvalid RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_INVALID 31 + 32 + // RenderStateDataCols is the viewport width in cells (uint16_t). 33 + RenderStateDataCols RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLS 34 + 35 + // RenderStateDataRows is the viewport height in cells (uint16_t). 36 + RenderStateDataRows RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_ROWS 37 + 38 + // RenderStateDataDirty is the current dirty state 39 + // (GhosttyRenderStateDirty). 40 + RenderStateDataDirty RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_DIRTY 41 + 42 + // RenderStateDataRowIterator populates a pre-allocated row iterator 43 + // (GhosttyRenderStateRowIterator). 44 + RenderStateDataRowIterator RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_ROW_ITERATOR 45 + 46 + // RenderStateDataColorBackground is the default/current background 47 + // color (GhosttyColorRgb). 48 + RenderStateDataColorBackground RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_BACKGROUND 49 + 50 + // RenderStateDataColorForeground is the default/current foreground 51 + // color (GhosttyColorRgb). 52 + RenderStateDataColorForeground RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_FOREGROUND 53 + 54 + // RenderStateDataColorCursor is the cursor color when explicitly set 55 + // (GhosttyColorRgb). 56 + RenderStateDataColorCursor RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_CURSOR 57 + 58 + // RenderStateDataColorCursorHasValue indicates whether an explicit 59 + // cursor color is set (bool). 60 + RenderStateDataColorCursorHasValue RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_CURSOR_HAS_VALUE 61 + 62 + // RenderStateDataColorPalette is the active 256-color palette 63 + // (GhosttyColorRgb[256]). 64 + RenderStateDataColorPalette RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_COLOR_PALETTE 65 + 66 + // RenderStateDataCursorVisualStyle is the visual style of the cursor 67 + // (GhosttyRenderStateCursorVisualStyle). 68 + RenderStateDataCursorVisualStyle RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VISUAL_STYLE 69 + 70 + // RenderStateDataCursorVisible indicates whether the cursor is visible 71 + // based on terminal modes (bool). 72 + RenderStateDataCursorVisible RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VISIBLE 73 + 74 + // RenderStateDataCursorBlinking indicates whether the cursor should 75 + // blink based on terminal modes (bool). 76 + RenderStateDataCursorBlinking RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_BLINKING 77 + 78 + // RenderStateDataCursorPasswordInput indicates whether the cursor is 79 + // at a password input field (bool). 80 + RenderStateDataCursorPasswordInput RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_PASSWORD_INPUT 81 + 82 + // RenderStateDataCursorViewportHasValue indicates whether the cursor 83 + // is visible within the viewport (bool). 84 + RenderStateDataCursorViewportHasValue RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_HAS_VALUE 85 + 86 + // RenderStateDataCursorViewportX is the cursor viewport x position 87 + // in cells (uint16_t). 88 + RenderStateDataCursorViewportX RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_X 89 + 90 + // RenderStateDataCursorViewportY is the cursor viewport y position 91 + // in cells (uint16_t). 92 + RenderStateDataCursorViewportY RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_Y 93 + 94 + // RenderStateDataCursorViewportWideTail indicates whether the cursor 95 + // is on the tail of a wide character (bool). 96 + RenderStateDataCursorViewportWideTail RenderStateData = C.GHOSTTY_RENDER_STATE_DATA_CURSOR_VIEWPORT_WIDE_TAIL 97 + ) 98 + 23 99 // Cols returns the viewport width in cells. 24 100 func (rs *RenderState) Cols() (uint16, error) { 25 101 var v C.uint16_t ··· 104 180 result.Palette[i] = ColorRGB{R: uint8(c.r), G: uint8(c.g), B: uint8(c.b)} 105 181 } 106 182 return result, nil 183 + } 184 + 185 + // GetMulti queries multiple render state data fields in a single cgo 186 + // call. This is a low-level function; prefer the typed getters (Cols, 187 + // Rows, CursorVisible, etc.) for normal use. GetMulti is useful when 188 + // you need many fields at once and want to avoid per-field cgo overhead. 189 + // 190 + // Each element in keys specifies a data kind, and the corresponding 191 + // element in values must be an unsafe.Pointer to a variable whose type 192 + // matches the "Output type" documented for that key in the upstream C 193 + // header (ghostty/vt/render.h, GhosttyRenderStateData enum). 194 + // 195 + // Example: 196 + // 197 + // var cols, rows C.uint16_t 198 + // err := rs.GetMulti( 199 + // []RenderStateData{RenderStateDataCols, RenderStateDataRows}, 200 + // []unsafe.Pointer{unsafe.Pointer(&cols), unsafe.Pointer(&rows)}, 201 + // ) 202 + // 203 + // C: ghostty_render_state_get_multi 204 + func (rs *RenderState) GetMulti(keys []RenderStateData, values []unsafe.Pointer) error { 205 + if len(keys) != len(values) { 206 + return errors.New("libghostty: keys and values must have the same length") 207 + } 208 + if len(keys) == 0 { 209 + return nil 210 + } 211 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 212 + cVals := cValuesArray(values) 213 + defer C.free(unsafe.Pointer(cVals)) 214 + return resultError(C.ghostty_render_state_get_multi( 215 + rs.ptr, 216 + C.size_t(len(keys)), 217 + (*C.GhosttyRenderStateData)(unsafe.Pointer(&keys[0])), 218 + cVals, 219 + nil, 220 + )) 107 221 } 108 222 109 223 // CursorBlinking reports whether the cursor should blink based on
+64 -1
render_state_row.go
··· 4 4 // GhosttyRenderStateRowIterator C APIs. 5 5 6 6 /* 7 + #include <stdlib.h> 7 8 #include <ghostty/vt.h> 8 9 */ 9 10 import "C" 10 11 11 - import "unsafe" 12 + import ( 13 + "errors" 14 + "unsafe" 15 + ) 16 + 17 + // RenderStateRowData identifies a data field for render state row queries. 18 + // C: GhosttyRenderStateRowData 19 + type RenderStateRowData int 20 + 21 + const ( 22 + // RenderStateRowDataInvalid is an invalid / sentinel value. 23 + RenderStateRowDataInvalid RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_INVALID 24 + 25 + // RenderStateRowDataDirty indicates whether the current row is dirty 26 + // (bool). 27 + RenderStateRowDataDirty RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_DIRTY 28 + 29 + // RenderStateRowDataRaw is the raw row value (GhosttyRow). 30 + RenderStateRowDataRaw RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_RAW 31 + 32 + // RenderStateRowDataCells populates a pre-allocated row cells instance 33 + // (GhosttyRenderStateRowCells). 34 + RenderStateRowDataCells RenderStateRowData = C.GHOSTTY_RENDER_STATE_ROW_DATA_CELLS 35 + ) 12 36 13 37 // RenderStateRowIterator iterates over rows in a render state. 14 38 // Create one with NewRenderStateRowIterator, populate it via ··· 45 69 // false when there are no more rows. 46 70 func (ri *RenderStateRowIterator) Next() bool { 47 71 return bool(C.ghostty_render_state_row_iterator_next(ri.ptr)) 72 + } 73 + 74 + // GetMulti queries multiple render-state row data fields in a single 75 + // cgo call. This is a low-level function; prefer the typed getters 76 + // (Dirty, Raw, Cells) for normal use. GetMulti is useful when you 77 + // need many fields at once and want to avoid per-field cgo overhead. 78 + // 79 + // Each element in keys specifies a data kind, and the corresponding 80 + // element in values must be an unsafe.Pointer to a variable whose type 81 + // matches the "Output type" documented for that key in the upstream C 82 + // header (ghostty/vt/render.h, GhosttyRenderStateRowData enum). 83 + // 84 + // Example: 85 + // 86 + // var dirty C.bool 87 + // var raw C.GhosttyRow 88 + // err := ri.GetMulti( 89 + // []RenderStateRowData{RenderStateRowDataDirty, RenderStateRowDataRaw}, 90 + // []unsafe.Pointer{unsafe.Pointer(&dirty), unsafe.Pointer(&raw)}, 91 + // ) 92 + // 93 + // C: ghostty_render_state_row_get_multi 94 + func (ri *RenderStateRowIterator) GetMulti(keys []RenderStateRowData, values []unsafe.Pointer) error { 95 + if len(keys) != len(values) { 96 + return errors.New("libghostty: keys and values must have the same length") 97 + } 98 + if len(keys) == 0 { 99 + return nil 100 + } 101 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 102 + cVals := cValuesArray(values) 103 + defer C.free(unsafe.Pointer(cVals)) 104 + return resultError(C.ghostty_render_state_row_get_multi( 105 + ri.ptr, 106 + C.size_t(len(keys)), 107 + (*C.GhosttyRenderStateRowData)(unsafe.Pointer(&keys[0])), 108 + cVals, 109 + nil, 110 + )) 48 111 } 49 112 50 113 // Dirty reports whether the current row is dirty and requires a
+171 -1
screen.go
··· 1 1 package libghostty 2 2 3 3 /* 4 + #include <stdlib.h> 4 5 #include <ghostty/vt.h> 5 6 */ 6 7 import "C" 7 8 8 - import "unsafe" 9 + import ( 10 + "errors" 11 + "unsafe" 12 + ) 13 + 14 + // CellData identifies a data field for cell queries. 15 + // C: GhosttyCellData 16 + type CellData int 17 + 18 + const ( 19 + // CellDataInvalid is an invalid data type. 20 + CellDataInvalid CellData = C.GHOSTTY_CELL_DATA_INVALID 21 + 22 + // CellDataCodepoint is the codepoint of the cell (uint32_t). 23 + CellDataCodepoint CellData = C.GHOSTTY_CELL_DATA_CODEPOINT 24 + 25 + // CellDataContentTag is the content tag describing what kind of 26 + // content is in the cell (GhosttyCellContentTag). 27 + CellDataContentTag CellData = C.GHOSTTY_CELL_DATA_CONTENT_TAG 28 + 29 + // CellDataWide is the wide property of the cell (GhosttyCellWide). 30 + CellDataWide CellData = C.GHOSTTY_CELL_DATA_WIDE 31 + 32 + // CellDataHasText indicates whether the cell has text to render (bool). 33 + CellDataHasText CellData = C.GHOSTTY_CELL_DATA_HAS_TEXT 34 + 35 + // CellDataHasStyling indicates whether the cell has non-default 36 + // styling (bool). 37 + CellDataHasStyling CellData = C.GHOSTTY_CELL_DATA_HAS_STYLING 38 + 39 + // CellDataStyleID is the style ID for the cell (uint16_t). 40 + CellDataStyleID CellData = C.GHOSTTY_CELL_DATA_STYLE_ID 41 + 42 + // CellDataHasHyperlink indicates whether the cell has a hyperlink 43 + // (bool). 44 + CellDataHasHyperlink CellData = C.GHOSTTY_CELL_DATA_HAS_HYPERLINK 45 + 46 + // CellDataProtected indicates whether the cell is protected (bool). 47 + CellDataProtected CellData = C.GHOSTTY_CELL_DATA_PROTECTED 48 + 49 + // CellDataSemanticContent is the semantic content type of the cell 50 + // (GhosttyCellSemanticContent). 51 + CellDataSemanticContent CellData = C.GHOSTTY_CELL_DATA_SEMANTIC_CONTENT 52 + 53 + // CellDataColorPalette is the palette index for the cell's background 54 + // color (GhosttyColorPaletteIndex). 55 + CellDataColorPalette CellData = C.GHOSTTY_CELL_DATA_COLOR_PALETTE 56 + 57 + // CellDataColorRGBValue is the RGB value for the cell's background 58 + // color (GhosttyColorRgb). 59 + CellDataColorRGBValue CellData = C.GHOSTTY_CELL_DATA_COLOR_RGB 60 + ) 61 + 62 + // RowData identifies a data field for row queries. 63 + // C: GhosttyRowData 64 + type RowData int 65 + 66 + const ( 67 + // RowDataInvalid is an invalid data type. 68 + RowDataInvalid RowData = C.GHOSTTY_ROW_DATA_INVALID 69 + 70 + // RowDataWrap indicates whether the row is soft-wrapped (bool). 71 + RowDataWrap RowData = C.GHOSTTY_ROW_DATA_WRAP 72 + 73 + // RowDataWrapContinuation indicates whether the row is a continuation 74 + // of a soft-wrapped row (bool). 75 + RowDataWrapContinuation RowData = C.GHOSTTY_ROW_DATA_WRAP_CONTINUATION 76 + 77 + // RowDataGrapheme indicates whether any cells in the row have grapheme 78 + // clusters (bool). 79 + RowDataGrapheme RowData = C.GHOSTTY_ROW_DATA_GRAPHEME 80 + 81 + // RowDataStyled indicates whether any cells in the row have styling 82 + // (bool). 83 + RowDataStyled RowData = C.GHOSTTY_ROW_DATA_STYLED 84 + 85 + // RowDataHyperlink indicates whether any cells in the row have 86 + // hyperlinks (bool). 87 + RowDataHyperlink RowData = C.GHOSTTY_ROW_DATA_HYPERLINK 88 + 89 + // RowDataSemanticPrompt is the semantic prompt state of the row 90 + // (GhosttyRowSemanticPrompt). 91 + RowDataSemanticPrompt RowData = C.GHOSTTY_ROW_DATA_SEMANTIC_PROMPT 92 + 93 + // RowDataKittyVirtualPlaceholder indicates whether the row contains 94 + // a Kitty virtual placeholder (bool). 95 + RowDataKittyVirtualPlaceholder RowData = C.GHOSTTY_ROW_DATA_KITTY_VIRTUAL_PLACEHOLDER 96 + 97 + // RowDataDirty indicates whether the row is dirty and requires a 98 + // redraw (bool). 99 + RowDataDirty RowData = C.GHOSTTY_ROW_DATA_DIRTY 100 + ) 9 101 10 102 // Cell is a wrapper around an opaque terminal grid cell value. 11 103 // Use getter methods to extract data from it. ··· 93 185 RowSemanticPromptContinuation RowSemanticPrompt = C.GHOSTTY_ROW_SEMANTIC_PROMPT_CONTINUATION 94 186 ) 95 187 188 + // GetMulti queries multiple cell data fields in a single cgo call. 189 + // This is a low-level function; prefer the typed getters (Codepoint, 190 + // Wide, HasText, etc.) for normal use. GetMulti is useful when you 191 + // need many fields at once and want to avoid per-field cgo overhead. 192 + // 193 + // Each element in keys specifies a data kind, and the corresponding 194 + // element in values must be an unsafe.Pointer to a variable whose type 195 + // matches the "Output type" documented for that key in the upstream C 196 + // header (ghostty/vt/screen.h, GhosttyCellData enum). 197 + // 198 + // Example: 199 + // 200 + // var cp C.uint32_t 201 + // var wide C.GhosttyCellWide 202 + // err := cell.GetMulti( 203 + // []CellData{CellDataCodepoint, CellDataWide}, 204 + // []unsafe.Pointer{unsafe.Pointer(&cp), unsafe.Pointer(&wide)}, 205 + // ) 206 + // 207 + // C: ghostty_cell_get_multi 208 + func (c *Cell) GetMulti(keys []CellData, values []unsafe.Pointer) error { 209 + if len(keys) != len(values) { 210 + return errors.New("libghostty: keys and values must have the same length") 211 + } 212 + if len(keys) == 0 { 213 + return nil 214 + } 215 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 216 + cVals := cValuesArray(values) 217 + defer C.free(unsafe.Pointer(cVals)) 218 + return resultError(C.ghostty_cell_get_multi( 219 + c.c, 220 + C.size_t(len(keys)), 221 + (*C.GhosttyCellData)(unsafe.Pointer(&keys[0])), 222 + cVals, 223 + nil, 224 + )) 225 + } 226 + 96 227 // Codepoint returns the codepoint of the cell (0 if empty). 97 228 func (c *Cell) Codepoint() (uint32, error) { 98 229 var v C.uint32_t ··· 193 324 return ColorRGB{}, err 194 325 } 195 326 return ColorRGB{R: uint8(v.r), G: uint8(v.g), B: uint8(v.b)}, nil 327 + } 328 + 329 + // GetMulti queries multiple row data fields in a single cgo call. 330 + // This is a low-level function; prefer the typed getters (Wrap, 331 + // Grapheme, Styled, Semantic, etc.) for normal use. GetMulti is 332 + // useful when you need many fields at once and want to avoid 333 + // per-field cgo overhead. 334 + // 335 + // Each element in keys specifies a data kind, and the corresponding 336 + // element in values must be an unsafe.Pointer to a variable whose type 337 + // matches the "Output type" documented for that key in the upstream C 338 + // header (ghostty/vt/screen.h, GhosttyRowData enum). 339 + // 340 + // Example: 341 + // 342 + // var wrap, styled C.bool 343 + // err := row.GetMulti( 344 + // []RowData{RowDataWrap, RowDataStyled}, 345 + // []unsafe.Pointer{unsafe.Pointer(&wrap), unsafe.Pointer(&styled)}, 346 + // ) 347 + // 348 + // C: ghostty_row_get_multi 349 + func (r *Row) GetMulti(keys []RowData, values []unsafe.Pointer) error { 350 + if len(keys) != len(values) { 351 + return errors.New("libghostty: keys and values must have the same length") 352 + } 353 + if len(keys) == 0 { 354 + return nil 355 + } 356 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 357 + cVals := cValuesArray(values) 358 + defer C.free(unsafe.Pointer(cVals)) 359 + return resultError(C.ghostty_row_get_multi( 360 + r.c, 361 + C.size_t(len(keys)), 362 + (*C.GhosttyRowData)(unsafe.Pointer(&keys[0])), 363 + cVals, 364 + nil, 365 + )) 196 366 } 197 367 198 368 // Wrap reports whether the row is soft-wrapped.
+162
terminal_data.go
··· 4 4 // Functions are ordered alphabetically. 5 5 6 6 /* 7 + #include <stdlib.h> 7 8 #include <ghostty/vt.h> 8 9 */ 9 10 import "C" ··· 13 14 "unsafe" 14 15 ) 15 16 17 + // TerminalData identifies a data field for terminal queries. 18 + // C: GhosttyTerminalData 19 + type TerminalData int 20 + 21 + const ( 22 + // TerminalDataInvalid is an invalid / sentinel value. 23 + TerminalDataInvalid TerminalData = C.GHOSTTY_TERMINAL_DATA_INVALID 24 + 25 + // TerminalDataCols is the terminal width in cells (uint16_t). 26 + TerminalDataCols TerminalData = C.GHOSTTY_TERMINAL_DATA_COLS 27 + 28 + // TerminalDataRows is the terminal height in cells (uint16_t). 29 + TerminalDataRows TerminalData = C.GHOSTTY_TERMINAL_DATA_ROWS 30 + 31 + // TerminalDataCursorX is the cursor column position, 0-indexed (uint16_t). 32 + TerminalDataCursorX TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_X 33 + 34 + // TerminalDataCursorY is the cursor row position within the active area, 35 + // 0-indexed (uint16_t). 36 + TerminalDataCursorY TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_Y 37 + 38 + // TerminalDataCursorPendingWrap indicates whether the cursor has a 39 + // pending wrap (bool). 40 + TerminalDataCursorPendingWrap TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_PENDING_WRAP 41 + 42 + // TerminalDataActiveScreen is the currently active screen 43 + // (GhosttyTerminalScreen). 44 + TerminalDataActiveScreen TerminalData = C.GHOSTTY_TERMINAL_DATA_ACTIVE_SCREEN 45 + 46 + // TerminalDataCursorVisible indicates whether the cursor is visible, 47 + // DEC mode 25 (bool). 48 + TerminalDataCursorVisible TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_VISIBLE 49 + 50 + // TerminalDataKittyKeyboardFlags is the current Kitty keyboard protocol 51 + // flags (uint8_t). 52 + TerminalDataKittyKeyboardFlags TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_KEYBOARD_FLAGS 53 + 54 + // TerminalDataScrollbar is the scrollbar state for the terminal viewport 55 + // (GhosttyTerminalScrollbar). 56 + TerminalDataScrollbar TerminalData = C.GHOSTTY_TERMINAL_DATA_SCROLLBAR 57 + 58 + // TerminalDataCursorStyle is the current SGR style of the cursor 59 + // (GhosttyStyle). 60 + TerminalDataCursorStyle TerminalData = C.GHOSTTY_TERMINAL_DATA_CURSOR_STYLE 61 + 62 + // TerminalDataMouseTracking indicates whether any mouse tracking mode 63 + // is active (bool). 64 + TerminalDataMouseTracking TerminalData = C.GHOSTTY_TERMINAL_DATA_MOUSE_TRACKING 65 + 66 + // TerminalDataTitle is the terminal title as set by escape sequences 67 + // (GhosttyString). 68 + TerminalDataTitle TerminalData = C.GHOSTTY_TERMINAL_DATA_TITLE 69 + 70 + // TerminalDataPwd is the terminal's current working directory as set 71 + // by escape sequences (GhosttyString). 72 + TerminalDataPwd TerminalData = C.GHOSTTY_TERMINAL_DATA_PWD 73 + 74 + // TerminalDataTotalRows is the total number of rows in the active screen 75 + // including scrollback (size_t). 76 + TerminalDataTotalRows TerminalData = C.GHOSTTY_TERMINAL_DATA_TOTAL_ROWS 77 + 78 + // TerminalDataScrollbackRows is the number of scrollback rows (size_t). 79 + TerminalDataScrollbackRows TerminalData = C.GHOSTTY_TERMINAL_DATA_SCROLLBACK_ROWS 80 + 81 + // TerminalDataWidthPx is the total terminal width in pixels (uint32_t). 82 + TerminalDataWidthPx TerminalData = C.GHOSTTY_TERMINAL_DATA_WIDTH_PX 83 + 84 + // TerminalDataHeightPx is the total terminal height in pixels (uint32_t). 85 + TerminalDataHeightPx TerminalData = C.GHOSTTY_TERMINAL_DATA_HEIGHT_PX 86 + 87 + // TerminalDataColorForeground is the effective foreground color 88 + // (GhosttyColorRgb). 89 + TerminalDataColorForeground TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND 90 + 91 + // TerminalDataColorBackground is the effective background color 92 + // (GhosttyColorRgb). 93 + TerminalDataColorBackground TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND 94 + 95 + // TerminalDataColorCursor is the effective cursor color 96 + // (GhosttyColorRgb). 97 + TerminalDataColorCursor TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_CURSOR 98 + 99 + // TerminalDataColorPalette is the current 256-color palette 100 + // (GhosttyColorRgb[256]). 101 + TerminalDataColorPalette TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_PALETTE 102 + 103 + // TerminalDataColorForegroundDefault is the default foreground color, 104 + // ignoring OSC overrides (GhosttyColorRgb). 105 + TerminalDataColorForegroundDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_FOREGROUND_DEFAULT 106 + 107 + // TerminalDataColorBackgroundDefault is the default background color, 108 + // ignoring OSC overrides (GhosttyColorRgb). 109 + TerminalDataColorBackgroundDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_BACKGROUND_DEFAULT 110 + 111 + // TerminalDataColorCursorDefault is the default cursor color, 112 + // ignoring OSC overrides (GhosttyColorRgb). 113 + TerminalDataColorCursorDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_CURSOR_DEFAULT 114 + 115 + // TerminalDataColorPaletteDefault is the default 256-color palette, 116 + // ignoring OSC overrides (GhosttyColorRgb[256]). 117 + TerminalDataColorPaletteDefault TerminalData = C.GHOSTTY_TERMINAL_DATA_COLOR_PALETTE_DEFAULT 118 + 119 + // TerminalDataKittyImageStorageLimit is the Kitty image storage limit 120 + // in bytes for the active screen (uint64_t). 121 + TerminalDataKittyImageStorageLimit TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_STORAGE_LIMIT 122 + 123 + // TerminalDataKittyImageMediumFile indicates whether the file medium 124 + // is enabled for Kitty image loading (bool). 125 + TerminalDataKittyImageMediumFile TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_FILE 126 + 127 + // TerminalDataKittyImageMediumTempFile indicates whether the temporary 128 + // file medium is enabled for Kitty image loading (bool). 129 + TerminalDataKittyImageMediumTempFile TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_TEMP_FILE 130 + 131 + // TerminalDataKittyImageMediumSharedMem indicates whether the shared 132 + // memory medium is enabled for Kitty image loading (bool). 133 + TerminalDataKittyImageMediumSharedMem TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_IMAGE_MEDIUM_SHARED_MEM 134 + 135 + // TerminalDataKittyGraphics is the Kitty graphics image storage for 136 + // the active screen (GhosttyKittyGraphics). 137 + TerminalDataKittyGraphics TerminalData = C.GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS 138 + ) 139 + 16 140 // ActiveScreen returns which screen buffer is currently active. 17 141 func (t *Terminal) ActiveScreen() (TerminalScreen, error) { 18 142 var v C.GhosttyTerminalScreen ··· 77 201 // any OSC overrides. 78 202 func (t *Terminal) ColorPaletteDefault() (*Palette, error) { 79 203 return t.getPalette(C.GHOSTTY_TERMINAL_DATA_COLOR_PALETTE_DEFAULT) 204 + } 205 + 206 + // GetMulti queries multiple terminal data fields in a single cgo call. 207 + // This is a low-level function; prefer the typed getters (Cols, Rows, 208 + // CursorX, etc.) for normal use. GetMulti is useful when you need many 209 + // fields at once and want to avoid per-field cgo overhead. 210 + // 211 + // Each element in keys specifies a data kind, and the corresponding 212 + // element in values must be an unsafe.Pointer to a variable whose type 213 + // matches the "Output type" documented for that key in the upstream C 214 + // header (ghostty/vt/terminal.h, GhosttyTerminalData enum). 215 + // 216 + // Example: 217 + // 218 + // var cols, rows C.uint16_t 219 + // err := t.GetMulti( 220 + // []TerminalData{TerminalDataCols, TerminalDataRows}, 221 + // []unsafe.Pointer{unsafe.Pointer(&cols), unsafe.Pointer(&rows)}, 222 + // ) 223 + // 224 + // C: ghostty_terminal_get_multi 225 + func (t *Terminal) GetMulti(keys []TerminalData, values []unsafe.Pointer) error { 226 + if len(keys) != len(values) { 227 + return errors.New("libghostty: keys and values must have the same length") 228 + } 229 + if len(keys) == 0 { 230 + return nil 231 + } 232 + // Allocate the void** array in C memory to satisfy cgo pointer-passing rules. 233 + cVals := cValuesArray(values) 234 + defer C.free(unsafe.Pointer(cVals)) 235 + return resultError(C.ghostty_terminal_get_multi( 236 + t.ptr, 237 + C.size_t(len(keys)), 238 + (*C.GhosttyTerminalData)(unsafe.Pointer(&keys[0])), 239 + cVals, 240 + nil, 241 + )) 80 242 } 81 243 82 244 // CursorPendingWrap reports whether the cursor has a pending wrap