use proper type for optional path

This commit is contained in:
Mitchell Hashimoto
2026-03-03 19:53:15 -08:00
parent b215291914
commit 98ad1d955c
5 changed files with 28 additions and 11 deletions

View File

@@ -463,6 +463,12 @@ typedef struct {
// Config types
// config.Path
typedef struct {
const char* path;
bool optional;
} ghostty_config_path_s;
// config.Color
typedef struct {
uint8_t r;

View File

@@ -778,8 +778,8 @@ class AppDelegate: NSObject,
}
if ghostty.config.bellFeatures.contains(.audio) {
if let path = ghostty.config.bellAudioPath,
let sound = NSSound(contentsOfFile: path, byReference: false) {
if let configPath = ghostty.config.bellAudioPath,
let sound = NSSound(contentsOfFile: configPath.path, byReference: false) {
sound.volume = ghostty.config.bellAudioVolume
sound.play()
}

View File

@@ -134,14 +134,13 @@ extension Ghostty {
return .init(rawValue: v)
}
var bellAudioPath: String? {
var bellAudioPath: ConfigPath? {
guard let config = self.config else { return nil }
var v: UnsafePointer<Int8>?
var v = ghostty_config_path_s()
let key = "bell-audio-path"
guard ghostty_config_get(config, &v, key, UInt(key.lengthOfBytes(using: .utf8))) else { return nil }
guard let ptr = v else { return nil }
let path = String(cString: ptr)
return path.isEmpty ? nil : path
let path = String(cString: v.path)
return path.isEmpty ? nil : ConfigPath(path: path, optional: v.optional)
}
var bellAudioVolume: Float {

View File

@@ -2,6 +2,12 @@
// can get typed information without depending on all the dependencies of GhosttyKit.
extension Ghostty {
/// A configuration path value that may be optional or required.
struct ConfigPath: Sendable {
let path: String
let optional: Bool
}
/// macos-icon
enum MacOSIcon: String, Sendable {
case official

View File

@@ -32,11 +32,17 @@ pub const Path = union(enum) {
return std.meta.eql(self, other);
}
/// Returns the path as a C-compatible null-terminated string pointer.
pub fn cval(self: Path) [*:0]const u8 {
/// ghostty_config_path_s
pub const C = extern struct {
path: [*:0]const u8,
optional: bool,
};
/// Returns the path as a C-compatible struct.
pub fn cval(self: Path) C {
return switch (self) {
.optional => |path| path.ptr,
.required => |path| path.ptr,
.optional => |path| .{ .path = path.ptr, .optional = true },
.required => |path| .{ .path = path.ptr, .optional = false },
};
}