diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-09-10 21:51:57 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-10 21:51:57 +0300 |
| commit | 425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch) | |
| tree | e52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/config/file_load.zig | |
| parent | 90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff) | |
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/config/file_load.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/config/file_load.zig | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/vendor/libghostty-vt/src/config/file_load.zig b/vendor/libghostty-vt/src/config/file_load.zig index 7885de32..7495e899 100644 --- a/vendor/libghostty-vt/src/config/file_load.zig +++ b/vendor/libghostty-vt/src/config/file_load.zig @@ -3,14 +3,19 @@ const builtin = @import("builtin"); const assert = @import("../quirks.zig").inlineAssert; const Allocator = std.mem.Allocator; const internal_os = @import("../os/main.zig"); +const global = @import("../global.zig"); const log = std.log.scoped(.config); /// Default path for the XDG home configuration file. Returned value /// must be freed by the caller. pub fn defaultXdgPath(alloc: Allocator) ![]const u8 { + var environ_map = try global.environMap(); + defer environ_map.deinit(); return try internal_os.xdg.config( + global.io(), alloc, + &environ_map, .{ .subdir = "ghostty/config.ghostty" }, ); } @@ -18,8 +23,12 @@ pub fn defaultXdgPath(alloc: Allocator) ![]const u8 { /// Ghostty <1.3.0 default path for the XDG home configuration file. /// Returned value must be freed by the caller. pub fn legacyDefaultXdgPath(alloc: Allocator) ![]const u8 { + var environ_map = try global.environMap(); + defer environ_map.deinit(); return try internal_os.xdg.config( + global.io(), alloc, + &environ_map, .{ .subdir = "ghostty/config" }, ); } @@ -29,16 +38,16 @@ pub fn legacyDefaultXdgPath(alloc: Allocator) ![]const u8 { pub fn preferredXdgPath(alloc: Allocator) ![]const u8 { // If the XDG path exists, use that. const xdg_path = try defaultXdgPath(alloc); - if (open(xdg_path)) |f| { - f.close(); + if (open(global.io(), xdg_path)) |f| { + f.close(global.io()); return xdg_path; } else |_| {} // Try the legacy path errdefer alloc.free(xdg_path); const legacy_xdg_path = try legacyDefaultXdgPath(alloc); - if (open(legacy_xdg_path)) |f| { - f.close(); + if (open(global.io(), legacy_xdg_path)) |f| { + f.close(global.io()); alloc.free(xdg_path); return legacy_xdg_path; } else |_| {} @@ -66,16 +75,16 @@ pub fn legacyDefaultAppSupportPath(alloc: Allocator) ![]const u8 { pub fn preferredAppSupportPath(alloc: Allocator) ![]const u8 { // If the app support path exists, use that. const app_support_path = try defaultAppSupportPath(alloc); - if (open(app_support_path)) |f| { - f.close(); + if (open(global.io(), app_support_path)) |f| { + f.close(global.io()); return app_support_path; } else |_| {} // Try the legacy path errdefer alloc.free(app_support_path); const legacy_app_support_path = try legacyDefaultAppSupportPath(alloc); - if (open(legacy_app_support_path)) |f| { - f.close(); + if (open(global.io(), legacy_app_support_path)) |f| { + f.close(global.io()); alloc.free(app_support_path); return legacy_app_support_path; } else |_| {} @@ -99,19 +108,19 @@ pub fn preferredDefaultFilePath(alloc: Allocator) ![]const u8 { // macOS prefers the Application Support directory // if it exists. const app_support_path = try preferredAppSupportPath(alloc); - const app_support_file = open(app_support_path) catch { + const app_support_file = open(global.io(), app_support_path) catch { // Try the XDG path if it exists const xdg_path = try preferredXdgPath(alloc); - const xdg_file = open(xdg_path) catch { + const xdg_file = open(global.io(), xdg_path) catch { // If neither file exists, use app support alloc.free(xdg_path); return app_support_path; }; - xdg_file.close(); + xdg_file.close(global.io()); alloc.free(app_support_path); return xdg_path; }; - app_support_file.close(); + app_support_file.close(global.io()); return app_support_path; }, @@ -130,10 +139,11 @@ const OpenFileError = error{ /// Opens the file at the given path and returns the file handle /// if it exists and is non-empty. This also constrains the possible /// errors to a smaller set that we can explicitly handle. -pub fn open(path: []const u8) OpenFileError!std.fs.File { +pub fn open(io: std.Io, path: []const u8) OpenFileError!std.Io.File { assert(std.fs.path.isAbsolute(path)); - var file = std.fs.openFileAbsolute( + var file = std.Io.Dir.openFileAbsolute( + io, path, .{}, ) catch |err| switch (err) { @@ -146,9 +156,9 @@ pub fn open(path: []const u8) OpenFileError!std.fs.File { return OpenFileError.FileOpenFailed; }, }; - errdefer file.close(); + errdefer file.close(io); - const stat = file.stat() catch |err| { + const stat = file.stat(io) catch |err| { log.warn("error getting file stat path={s} err={}", .{ path, err, |
