Add an enum type for the C API

This commit is contained in:
Peter Guy
2025-10-12 22:05:21 -07:00
parent 0af2a3f693
commit c035fb5385
2 changed files with 22 additions and 8 deletions

View File

@@ -416,6 +416,12 @@ typedef union {
ghostty_platform_ios_s ios;
} ghostty_platform_u;
typedef enum {
GHOSTTY_SURFACE_CONTEXT_WINDOW = 0,
GHOSTTY_SURFACE_CONTEXT_TAB = 1,
GHOSTTY_SURFACE_CONTEXT_SPLIT = 2,
} ghostty_surface_context_e;
typedef struct {
ghostty_platform_e platform_tag;
ghostty_platform_u platform;
@@ -428,7 +434,7 @@ typedef struct {
size_t env_var_count;
const char* initial_input;
bool wait_after_command;
int context; // 0=window, 1=tab, 2=split
ghostty_surface_context_e context;
} ghostty_surface_config_s;
typedef struct {

View File

@@ -625,11 +625,19 @@ extension Ghostty {
#endif
}
/// Context for surface creation, matching the Zig NewSurfaceContext enum
enum NewSurfaceContext: Int32 {
case window = 0
case tab = 1
case split = 2
/// Context for surface creation, matching ghostty_surface_context_e
enum NewSurfaceContext: ghostty_surface_context_e.RawValue {
case window = 0 // GHOSTTY_SURFACE_CONTEXT_WINDOW
case tab = 1 // GHOSTTY_SURFACE_CONTEXT_TAB
case split = 2 // GHOSTTY_SURFACE_CONTEXT_SPLIT
init(_ cValue: ghostty_surface_context_e) {
self.init(rawValue: cValue.rawValue)!
}
var cValue: ghostty_surface_context_e {
ghostty_surface_context_e(rawValue: self.rawValue)
}
}
/// The configuration for a surface. For any configuration not set, defaults will be chosen from
@@ -677,7 +685,7 @@ extension Ghostty {
}
}
}
self.context = NewSurfaceContext(rawValue: config.context) ?? .window
self.context = NewSurfaceContext(config.context)
}
/// Provides a C-compatible ghostty configuration within a closure. The configuration
@@ -712,7 +720,7 @@ extension Ghostty {
config.wait_after_command = waitAfterCommand
// Set context
config.context = context.rawValue
config.context = context.cValue
// Use withCString to ensure strings remain valid for the duration of the closure
return try workingDirectory.withCString { cWorkingDir in