From f0ee2fb454a1e231f8a64e24f78c4e89e497ef8b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Sep 2023 09:39:58 -0700 Subject: [PATCH] macos: log configuration errors --- include/ghostty.h | 6 ++++++ macos/Sources/Ghostty/AppState.swift | 14 ++++++++++++++ src/config/CAPI.zig | 15 +++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index 94b69b829..ed66824ed 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -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); diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 12ece198b..40225b2b1 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -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..= 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 = "", +};