Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/ghostty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*,
Expand Down
19 changes: 19 additions & 0 deletions src/config/CApi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const conditional = @import("conditional.zig"); is currently unused in this file, which will fail Zig compilation (unused top-level declaration). Either remove the import or use it (e.g., parse scheme_raw via std.meta.intToEnum(conditional.State.Theme, …) and assign the result).

Suggested change
const conditional = @import("conditional.zig");

Copilot uses AI. Check for mistakes.
const Config = @import("Config.zig");
const c_get = @import("c_get.zig");
const edit = @import("edit.zig");
Expand Down Expand Up @@ -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 {
Comment on lines +93 to +97
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new C API entry point isn’t covered by tests in this file. Since src/config/CApi.zig already has unit tests, add tests for ghostty_config_set_color_scheme verifying: (1) 0/1 set _conditional_state.theme to light/dark respectively, and (2) invalid values log a warning and do not modify the existing theme value.

Copilot uses AI. Check for mistakes.
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;
},
};
}
Comment on lines +97 to +109
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Inconsistent enum conversion pattern

The analogous functions ghostty_app_set_color_scheme and ghostty_surface_set_color_scheme in src/apprt/embedded.zig both use std.meta.intToEnum to validate and convert the raw integer, keeping a single conversion point that will produce a compile error if the enum grows. The new function hard-codes the integer literals instead, which diverges from that convention and silently becomes stale if conditional.State.Theme ever adds a variant with a non-sequential value.

Suggested change
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_set_color_scheme(self: *Config, scheme_raw: c_int) void {
self._conditional_state.theme = std.meta.intToEnum(
conditional.State.Theme,
scheme_raw,
) catch {
log.warn(
"invalid color scheme to ghostty_config_set_color_scheme value={}",
.{scheme_raw},
);
return;
};
}

Comment on lines +97 to +109
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing unit test

Every other exported function in this file has at least one Zig test (e.g. ghostty_config_get has six). A test that sets the scheme to dark before finalization and verifies _conditional_state.theme == .dark — and a second confirming the warning path leaves the state unchanged — would match the existing test pattern here.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


export fn ghostty_config_get(
self: *Config,
ptr: *anyopaque,
Expand Down
Loading