macos: load config file default file locations

This commit is contained in:
Mitchell Hashimoto
2023-03-03 09:01:13 -08:00
parent d8537732dd
commit 2a40bdabca
4 changed files with 26 additions and 2 deletions

View File

@ -221,6 +221,8 @@ int ghostty_init(void);
ghostty_config_t ghostty_config_new();
void ghostty_config_free(ghostty_config_t);
void ghostty_config_load_string(ghostty_config_t, const char *, uintptr_t);
void ghostty_config_load_default_files(ghostty_config_t);
void ghostty_config_load_recursive_files(ghostty_config_t);
void ghostty_config_finalize(ghostty_config_t);
ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s *, ghostty_config_t);

View File

@ -89,6 +89,10 @@ class GhosttyState: ObservableObject {
}
self.config = cfg;
// Load our configuration files from the home directory.
ghostty_config_load_default_files(cfg);
ghostty_config_load_recursive_files(cfg);
// TODO: we'd probably do some config loading here... for now we'd
// have to do this synchronously. When we support config updating we can do
// this async and update later.

View File

@ -342,7 +342,7 @@ pub const Config = struct {
}
/// Load and parse the config files that were added in the "config-file" key.
pub fn loadRecursive(self: *Config, alloc: Allocator) !void {
pub fn loadRecursiveFiles(self: *Config, alloc: Allocator) !void {
// TODO(mitchellh): we should parse the files form the homedir first
// TODO(mitchellh): support nesting (config-file in a config file)
// TODO(mitchellh): detect cycles when nesting
@ -708,6 +708,24 @@ pub const CAPI = struct {
try cli_args.parse(Config, global.alloc, self, &iter);
}
/// Load the configuration from the default file locations. This
/// is usually done first. The default file locations are locations
/// such as the home directory.
export fn ghostty_config_load_default_files(self: *Config) void {
self.loadDefaultFiles(global.alloc) catch |err| {
log.err("error loading config err={}", .{err});
};
}
/// Load the configuration from the user-specified configuration
/// file locations in the previously loaded configuration. This will
/// recursively continue to load up to a built-in limit.
export fn ghostty_config_load_recursive_files(self: *Config) void {
self.loadRecursiveFiles(global.alloc) catch |err| {
log.err("error loading config err={}", .{err});
};
}
export fn ghostty_config_finalize(self: *Config) void {
self.finalize() catch |err| {
log.err("error finalizing config err={}", .{err});

View File

@ -44,7 +44,7 @@ pub fn main() !void {
}
// Parse the config files that were added from our file and CLI args.
try config.loadRecursive(alloc);
try config.loadRecursiveFiles(alloc);
try config.finalize();
//std.log.debug("config={}", .{config});