Files
patterm/internal/vt/ghostty_cgo.go
2026-05-14 13:37:20 +01:00

39 lines
811 B
Go

//go:build !nocgo
package vt
/*
// This preamble must contain DECLARATIONS ONLY — cgo refuses to compile
// a file that both defines functions in its preamble and has //export
// directives. The helper definitions live in ghostty.go's preamble.
#include <stdint.h>
#include <stddef.h>
#include <ghostty/vt.h>
*/
import "C"
import (
"runtime/cgo"
"unsafe"
)
//export pattermGhosttyWritePty
func pattermGhosttyWritePty(_ C.GhosttyTerminal, userdata unsafe.Pointer, data *C.uint8_t, length C.size_t) {
if userdata == nil || data == nil || length == 0 {
return
}
h := cgo.Handle(uintptr(userdata))
v := h.Value()
e, ok := v.(*GhosttyEmulator)
if !ok || e == nil {
return
}
cb := e.writePTYCallback()
if cb == nil {
return
}
buf := C.GoBytes(unsafe.Pointer(data), C.int(length))
cb(buf)
}