mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 11:35:48 +00:00
move config loading to Config
This commit is contained in:
@@ -49,7 +49,7 @@ extension Ghostty {
|
||||
init(configPath: String? = nil) {
|
||||
self.configPath = configPath
|
||||
// Initialize the global configuration.
|
||||
self.config = configPath.flatMap({ Self.readConfig(at: $0, finalize: true) }) ?? Config()
|
||||
self.config = Config(at: configPath)
|
||||
if self.config.config == nil {
|
||||
readiness = .error
|
||||
return
|
||||
@@ -146,7 +146,7 @@ extension Ghostty {
|
||||
}
|
||||
|
||||
// Hard or full updates have to reload the full configuration
|
||||
let newConfig = configPath.flatMap({ Self.readConfig(at: $0, finalize: true) }) ?? Config()
|
||||
let newConfig = Config(at: configPath)
|
||||
guard newConfig.loaded else {
|
||||
Ghostty.logger.warning("failed to reload configuration")
|
||||
return
|
||||
@@ -166,7 +166,7 @@ extension Ghostty {
|
||||
// Hard or full updates have to reload the full configuration.
|
||||
// NOTE: We never set this on self.config because this is a surface-only
|
||||
// config. We free it after the call.
|
||||
let newConfig = configPath.flatMap({ Self.readConfig(at: $0, finalize: true) }) ?? Config()
|
||||
let newConfig = Config(at: configPath)
|
||||
guard newConfig.loaded else {
|
||||
Ghostty.logger.warning("failed to reload configuration")
|
||||
return
|
||||
@@ -2077,29 +2077,3 @@ extension Ghostty {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extension Ghostty.App {
|
||||
static func readConfig(at path: String, finalize: Bool = true) -> Ghostty.Config? {
|
||||
guard
|
||||
let cfg = ghostty_config_new()
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
if FileManager.default.fileExists(atPath: path) {
|
||||
ghostty_config_load_file(cfg, path)
|
||||
}
|
||||
#if os(macOS)
|
||||
if !isRunningInXcode() {
|
||||
ghostty_config_load_cli_args(cfg)
|
||||
}
|
||||
#endif
|
||||
ghostty_config_load_recursive_files(cfg)
|
||||
if finalize {
|
||||
// Finalize will make our defaults available,
|
||||
// and also will combine all the keys into one file,
|
||||
// we might not need this in the future
|
||||
ghostty_config_finalize(cfg)
|
||||
}
|
||||
return Ghostty.Config(config: cfg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ extension Ghostty {
|
||||
self.config = config
|
||||
}
|
||||
|
||||
convenience init() {
|
||||
self.init(config: Self.loadConfig())
|
||||
convenience init(at path: String? = nil, finalize: Bool = true) {
|
||||
self.init(config: Self.loadConfig(at: path, finalize: finalize))
|
||||
}
|
||||
|
||||
convenience init(clone config: ghostty_config_t) {
|
||||
@@ -50,7 +50,10 @@ extension Ghostty {
|
||||
}
|
||||
|
||||
/// Initializes a new configuration and loads all the values.
|
||||
static private func loadConfig() -> ghostty_config_t? {
|
||||
/// - Parameters:
|
||||
/// - path: An optional preferred config file path. Pass `nil` to load the default configuration files.
|
||||
/// - finalize: Whether to finalize the configuration to populate default values.
|
||||
static private func loadConfig(at path: String?, finalize: Bool) -> ghostty_config_t? {
|
||||
// Initialize the global configuration.
|
||||
guard let cfg = ghostty_config_new() else {
|
||||
logger.critical("ghostty_config_new failed")
|
||||
@@ -61,7 +64,11 @@ extension Ghostty {
|
||||
// We only do this on macOS because other Apple platforms do not have the
|
||||
// same filesystem concept.
|
||||
#if os(macOS)
|
||||
ghostty_config_load_default_files(cfg);
|
||||
if let path, FileManager.default.fileExists(atPath: path) {
|
||||
ghostty_config_load_file(cfg, path)
|
||||
} else {
|
||||
ghostty_config_load_default_files(cfg)
|
||||
}
|
||||
|
||||
// We only load CLI args when not running in Xcode because in Xcode we
|
||||
// pass some special parameters to control the debugger.
|
||||
@@ -76,9 +83,10 @@ extension Ghostty {
|
||||
// have to do this synchronously. When we support config updating we can do
|
||||
// this async and update later.
|
||||
|
||||
// Finalize will make our defaults available.
|
||||
ghostty_config_finalize(cfg)
|
||||
|
||||
if finalize {
|
||||
// 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 diagsCount = ghostty_config_diagnostics_count(cfg)
|
||||
|
||||
Reference in New Issue
Block a user