config: C API ghostty_config_clone

This commit is contained in:
Mitchell Hashimoto
2024-11-20 15:28:10 -08:00
parent 3afb9065f0
commit 037d4364e5
2 changed files with 18 additions and 0 deletions

View File

@ -646,6 +646,7 @@ ghostty_info_s ghostty_info(void);
ghostty_config_t ghostty_config_new(); ghostty_config_t ghostty_config_new();
void ghostty_config_free(ghostty_config_t); void ghostty_config_free(ghostty_config_t);
ghostty_config_t ghostty_config_clone(ghostty_config_t);
void ghostty_config_load_cli_args(ghostty_config_t); void ghostty_config_load_cli_args(ghostty_config_t);
void ghostty_config_load_default_files(ghostty_config_t); void ghostty_config_load_default_files(ghostty_config_t);
void ghostty_config_load_recursive_files(ghostty_config_t); void ghostty_config_load_recursive_files(ghostty_config_t);

View File

@ -19,6 +19,7 @@ export fn ghostty_config_new() ?*Config {
result.* = Config.default(global.alloc) catch |err| { result.* = Config.default(global.alloc) catch |err| {
log.err("error creating config err={}", .{err}); log.err("error creating config err={}", .{err});
global.alloc.destroy(result);
return null; return null;
}; };
@ -32,6 +33,22 @@ export fn ghostty_config_free(ptr: ?*Config) void {
} }
} }
/// Deep clone the configuration.
export fn ghostty_config_clone(self: *Config) ?*Config {
const result = global.alloc.create(Config) catch |err| {
log.err("error allocating config err={}", .{err});
return null;
};
result.* = self.clone(global.alloc) catch |err| {
log.err("error cloning config err={}", .{err});
global.alloc.destroy(result);
return null;
};
return result;
}
/// Load the configuration from the CLI args. /// Load the configuration from the CLI args.
export fn ghostty_config_load_cli_args(self: *Config) void { export fn ghostty_config_load_cli_args(self: *Config) void {
self.loadCliArgs(global.alloc) catch |err| { self.loadCliArgs(global.alloc) catch |err| {