macos: log configuration errors

This commit is contained in:
Mitchell Hashimoto
2023-09-11 09:39:58 -07:00
parent 9be46fa80a
commit f0ee2fb454
3 changed files with 35 additions and 0 deletions

View File

@ -250,6 +250,10 @@ typedef struct {
// Fully defined types. This MUST be kept in sync with equivalent Zig
// structs. To find the Zig struct, grep for this type name. The documentation
// for all of these types is available in the Zig source.
typedef struct {
const char *message;
} ghostty_error_s;
typedef struct {
void *userdata;
void *nsview;
@ -303,6 +307,8 @@ void ghostty_config_load_recursive_files(ghostty_config_t);
void ghostty_config_finalize(ghostty_config_t);
bool ghostty_config_get(ghostty_config_t, void *, const char *, uintptr_t);
ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t, const char *, uintptr_t);
uint32_t ghostty_config_errors_count(ghostty_config_t);
ghostty_error_s ghostty_config_get_error(ghostty_config_t, uint32_t);
ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s *, ghostty_config_t);
void ghostty_app_free(ghostty_app_t);

View File

@ -128,6 +128,20 @@ extension Ghostty {
// Finalize will make our defaults available.
ghostty_config_finalize(cfg)
// Log any configuration errors. These will be automatically shown in a
// pop-up window too.
let errCount = ghostty_config_errors_count(cfg)
if errCount > 0 {
AppDelegate.logger.warning("config error: \(errCount) configuration errors on reload")
var errors: [String] = [];
for i in 0..<errCount {
let err = ghostty_config_get_error(cfg, UInt32(i))
let message = String(cString: err.message)
errors.append(message)
AppDelegate.logger.warning("config error: \(message)")
}
}
return cfg
}

View File

@ -108,3 +108,18 @@ fn config_trigger_(
const action = try inputpkg.Binding.Action.parse(str);
return self.keybind.set.getTrigger(action) orelse .{};
}
export fn ghostty_config_errors_count(self: *Config) u32 {
return @intCast(self._errors.list.items.len);
}
export fn ghostty_config_get_error(self: *Config, idx: u32) Error {
if (idx >= self._errors.list.items.len) return .{};
const err = self._errors.list.items[idx];
return .{ .message = err.message.ptr };
}
/// Sync with ghostty_error_s
const Error = extern struct {
message: [*:0]const u8 = "",
};