Initial patterm project
This commit is contained in:
38
internal/vt/ghostty_cgo.go
Normal file
38
internal/vt/ghostty_cgo.go
Normal file
@@ -0,0 +1,38 @@
|
||||
//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)
|
||||
}
|
||||
Reference in New Issue
Block a user