mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
config: dedicated load func so we can reload
This commit is contained in:
@ -202,6 +202,34 @@ pub const Config = struct {
|
||||
self.* = undefined;
|
||||
}
|
||||
|
||||
/// Load the configuration according to the default rules:
|
||||
///
|
||||
/// 1. Defaults
|
||||
/// 2. XDG Config File
|
||||
/// 3. CLI flags
|
||||
/// 4. Recursively defined configuration files
|
||||
///
|
||||
pub fn load(alloc_gpa: Allocator) !Config {
|
||||
var result = try default(alloc_gpa);
|
||||
errdefer result.deinit();
|
||||
|
||||
// If we have a configuration file in our home directory, parse that first.
|
||||
try result.loadDefaultFiles(alloc_gpa);
|
||||
|
||||
// Parse the config from the CLI args
|
||||
{
|
||||
var iter = try std.process.argsWithAllocator(alloc_gpa);
|
||||
defer iter.deinit();
|
||||
try cli_args.parse(Config, alloc_gpa, &result, &iter);
|
||||
}
|
||||
|
||||
// Parse the config files that were added from our file and CLI args.
|
||||
try result.loadRecursiveFiles(alloc_gpa);
|
||||
try result.finalize();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn default(alloc_gpa: Allocator) Allocator.Error!Config {
|
||||
// Build up our basic config
|
||||
var result: Config = .{
|
||||
|
16
src/main.zig
16
src/main.zig
@ -30,22 +30,8 @@ pub fn main() !void {
|
||||
const alloc = state.alloc;
|
||||
|
||||
// Try reading our config
|
||||
var config = try Config.default(alloc);
|
||||
var config = try Config.load(alloc);
|
||||
defer config.deinit();
|
||||
|
||||
// If we have a configuration file in our home directory, parse that first.
|
||||
try config.loadDefaultFiles(alloc);
|
||||
|
||||
// Parse the config from the CLI args
|
||||
{
|
||||
var iter = try std.process.argsWithAllocator(alloc);
|
||||
defer iter.deinit();
|
||||
try cli_args.parse(Config, alloc, &config, &iter);
|
||||
}
|
||||
|
||||
// Parse the config files that were added from our file and CLI args.
|
||||
try config.loadRecursiveFiles(alloc);
|
||||
try config.finalize();
|
||||
//std.log.debug("config={}", .{config});
|
||||
|
||||
// Create our app state
|
||||
|
Reference in New Issue
Block a user