mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-19 14:00:29 +00:00
vt: add sized struct pattern and types.h
Add a size field as the first member of formatter option structs (TerminalOptions, TerminalOptions.Extra, ScreenOptions.Extra) for ABI compatibility. This allows adding new fields without breaking callers compiled against older versions of the struct. Introduce include/ghostty/vt/types.h as the foundational header containing GhosttyResult and the GHOSTTY_INIT_SIZED macro for zero-initializing sized structs. Remove the separate result.h header, moving its contents into types.h.
This commit is contained in:
@@ -8,3 +8,15 @@
|
||||
in `include/ghostty/vt.h`.
|
||||
- In `include/ghostty/vt.h`, always sort the header contents by:
|
||||
(1) macros, (2) forward declarations, (3) types, (4) functions
|
||||
|
||||
## ABI Compatibility
|
||||
|
||||
- Prefer opaque pointers for long-lived objects, such as
|
||||
`GhosttyTerminal`.
|
||||
- Structs:
|
||||
- May contain padding bytes if we're confident we'll never grow
|
||||
beyond a certain size.
|
||||
- May use the "sized struct" pattern: an `extern struct` with
|
||||
`size: usize = @sizeOf(Self)` as the first field. In the C header,
|
||||
callers use `GHOSTTY_INIT_SIZED` from `types.h` to zero-initialize and
|
||||
set the size.
|
||||
|
||||
@@ -27,6 +27,7 @@ pub const Format = formatterpkg.Format;
|
||||
pub const ScreenOptions = extern struct {
|
||||
/// C: GhosttyFormatterScreenExtra
|
||||
pub const Extra = extern struct {
|
||||
size: usize = @sizeOf(Extra),
|
||||
cursor: bool,
|
||||
style: bool,
|
||||
hyperlink: bool,
|
||||
@@ -56,6 +57,7 @@ pub const ScreenOptions = extern struct {
|
||||
|
||||
/// C: GhosttyFormatterTerminalOptions
|
||||
pub const TerminalOptions = extern struct {
|
||||
size: usize = @sizeOf(TerminalOptions),
|
||||
emit: Format,
|
||||
unwrap: bool,
|
||||
trim: bool,
|
||||
@@ -63,6 +65,7 @@ pub const TerminalOptions = extern struct {
|
||||
|
||||
/// C: GhosttyFormatterTerminalExtra
|
||||
pub const Extra = extern struct {
|
||||
size: usize = @sizeOf(Extra),
|
||||
palette: bool,
|
||||
modes: bool,
|
||||
scrolling_region: bool,
|
||||
|
||||
Reference in New Issue
Block a user