diff --git a/include/ghostty.h b/include/ghostty.h index 5186ad783..813f81df2 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -646,6 +646,7 @@ ghostty_info_s ghostty_info(void); ghostty_config_t ghostty_config_new(); 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_default_files(ghostty_config_t); void ghostty_config_load_recursive_files(ghostty_config_t); diff --git a/src/config/CAPI.zig b/src/config/CAPI.zig index bf86a0954..0b7108a59 100644 --- a/src/config/CAPI.zig +++ b/src/config/CAPI.zig @@ -19,6 +19,7 @@ export fn ghostty_config_new() ?*Config { result.* = Config.default(global.alloc) catch |err| { log.err("error creating config err={}", .{err}); + global.alloc.destroy(result); 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. export fn ghostty_config_load_cli_args(self: *Config) void { self.loadCliArgs(global.alloc) catch |err| {