diff --git a/include/ghostty.h b/include/ghostty.h index e7b6ae716f3..67681e6c8de 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -1073,6 +1073,8 @@ GHOSTTY_API void ghostty_config_load_file(ghostty_config_t, const char*); GHOSTTY_API void ghostty_config_load_default_files(ghostty_config_t); GHOSTTY_API void ghostty_config_load_recursive_files(ghostty_config_t); GHOSTTY_API void ghostty_config_finalize(ghostty_config_t); +GHOSTTY_API void ghostty_config_set_color_scheme(ghostty_config_t, + ghostty_color_scheme_e); GHOSTTY_API bool ghostty_config_get(ghostty_config_t, void*, const char*, uintptr_t); GHOSTTY_API ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t, const char*, diff --git a/src/config/CApi.zig b/src/config/CApi.zig index ca15ce4e89f..f72982f3854 100644 --- a/src/config/CApi.zig +++ b/src/config/CApi.zig @@ -3,6 +3,7 @@ const inputpkg = @import("../input.zig"); const state = &@import("../global.zig").state; const c = @import("../main_c.zig"); +const conditional = @import("conditional.zig"); const Config = @import("Config.zig"); const c_get = @import("c_get.zig"); const edit = @import("edit.zig"); @@ -89,6 +90,24 @@ export fn ghostty_config_finalize(self: *Config) void { }; } +/// Set the color scheme on a configuration's conditional state before +/// finalization. This ensures that conditional theme resolution (e.g. +/// `theme = light:Foo,dark:Bar`) uses the correct scheme during +/// `ghostty_config_finalize`. Must be called before finalize. +export fn ghostty_config_set_color_scheme(self: *Config, scheme_raw: c_int) void { + self._conditional_state.theme = switch (scheme_raw) { + 0 => .light, + 1 => .dark, + else => { + log.warn( + "invalid color scheme to ghostty_config_set_color_scheme value={}", + .{scheme_raw}, + ); + return; + }, + }; +} + export fn ghostty_config_get( self: *Config, ptr: *anyopaque,