From 18f2fb3fbdd6bd8e4f8fd6c58c0cfc4fa3df234f Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 20 Dec 2023 15:25:30 -0600 Subject: [PATCH] macos: include ghostty subdirectory under Resources This enables us to treat Ghostty's resources directory the same way whether it is installed in a macOS app bundle or under e.g. /usr/share. --- macos/Ghostty.xcodeproj/project.pbxproj | 12 ++++-------- src/os/resourcesdir.zig | 4 +--- src/termio/Exec.zig | 24 ++++++------------------ 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/macos/Ghostty.xcodeproj/project.pbxproj b/macos/Ghostty.xcodeproj/project.pbxproj index b635e16f0..67bd77598 100644 --- a/macos/Ghostty.xcodeproj/project.pbxproj +++ b/macos/Ghostty.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 55154BE02B33911F001622DC /* ghostty in Resources */ = {isa = PBXBuildFile; fileRef = 55154BDF2B33911F001622DC /* ghostty */; }; 8503D7C72A549C66006CFF3D /* FullScreenHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8503D7C62A549C66006CFF3D /* FullScreenHandler.swift */; }; 857F63812A5E64F200CA4815 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 857F63802A5E64F200CA4815 /* MainMenu.xib */; }; A51B78472AF4B58B00F3EDB9 /* TerminalWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51B78462AF4B58B00F3EDB9 /* TerminalWindow.swift */; }; @@ -18,7 +19,6 @@ A5278A9B2AA05B2600CD3039 /* Ghostty.Input.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5278A9A2AA05B2600CD3039 /* Ghostty.Input.swift */; }; A53426352A7DA53D00EBB7A2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53426342A7DA53D00EBB7A2 /* AppDelegate.swift */; }; A535B9DA299C569B0017E2E4 /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A535B9D9299C569B0017E2E4 /* ErrorView.swift */; }; - A545D1A22A5772CE006E0AE4 /* shell-integration in Resources */ = {isa = PBXBuildFile; fileRef = A545D1A12A5772CE006E0AE4 /* shell-integration */; }; A55685E029A03A9F004303CE /* AppError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A55685DF29A03A9F004303CE /* AppError.swift */; }; A55B7BB629B6F47F0055DE60 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = A55B7BB529B6F47F0055DE60 /* AppState.swift */; }; A55B7BB829B6F53A0055DE60 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = A55B7BB729B6F53A0055DE60 /* Package.swift */; }; @@ -39,7 +39,6 @@ A59FB5D12AE0DEA7009128F3 /* MetalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A59FB5D02AE0DEA7009128F3 /* MetalView.swift */; }; A5A1F8852A489D6800D1E8BC /* terminfo in Resources */ = {isa = PBXBuildFile; fileRef = A5A1F8842A489D6800D1E8BC /* terminfo */; }; A5B30539299BEAAB0047F10C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A5B30538299BEAAB0047F10C /* Assets.xcassets */; }; - A5CB04382B0F1C1C009ED217 /* themes in Resources */ = {isa = PBXBuildFile; fileRef = A5CB04372B0F1C1C009ED217 /* themes */; }; A5CDF1912AAF9A5800513312 /* ConfigurationErrors.xib in Resources */ = {isa = PBXBuildFile; fileRef = A5CDF1902AAF9A5800513312 /* ConfigurationErrors.xib */; }; A5CDF1932AAF9E0800513312 /* ConfigurationErrorsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CDF1922AAF9E0800513312 /* ConfigurationErrorsController.swift */; }; A5CDF1952AAFA19600513312 /* ConfigurationErrorsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5CDF1942AAFA19600513312 /* ConfigurationErrorsView.swift */; }; @@ -54,6 +53,7 @@ /* Begin PBXFileReference section */ 3B39CAA42B33949B00DABEB8 /* GhosttyReleaseLocal.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GhosttyReleaseLocal.entitlements; sourceTree = ""; }; + 55154BDF2B33911F001622DC /* ghostty */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ghostty; path = "../zig-out/share/ghostty"; sourceTree = ""; }; 8503D7C62A549C66006CFF3D /* FullScreenHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullScreenHandler.swift; sourceTree = ""; }; 857F63802A5E64F200CA4815 /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = ""; }; A51B78462AF4B58B00F3EDB9 /* TerminalWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalWindow.swift; sourceTree = ""; }; @@ -65,7 +65,6 @@ A5278A9A2AA05B2600CD3039 /* Ghostty.Input.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ghostty.Input.swift; sourceTree = ""; }; A53426342A7DA53D00EBB7A2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A535B9D9299C569B0017E2E4 /* ErrorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorView.swift; sourceTree = ""; }; - A545D1A12A5772CE006E0AE4 /* shell-integration */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "shell-integration"; path = "../zig-out/share/shell-integration"; sourceTree = ""; }; A55685DF29A03A9F004303CE /* AppError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppError.swift; sourceTree = ""; }; A55B7BB529B6F47F0055DE60 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = ""; }; A55B7BB729B6F53A0055DE60 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; @@ -88,7 +87,6 @@ A5B30531299BEAAA0047F10C /* Ghostty.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Ghostty.app; sourceTree = BUILT_PRODUCTS_DIR; }; A5B30538299BEAAB0047F10C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; A5B3053D299BEAAB0047F10C /* Ghostty.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Ghostty.entitlements; sourceTree = ""; }; - A5CB04372B0F1C1C009ED217 /* themes */ = {isa = PBXFileReference; lastKnownFileType = folder; name = themes; path = "../zig-out/share/themes"; sourceTree = ""; }; A5CDF1902AAF9A5800513312 /* ConfigurationErrors.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfigurationErrors.xib; sourceTree = ""; }; A5CDF1922AAF9E0800513312 /* ConfigurationErrorsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationErrorsController.swift; sourceTree = ""; }; A5CDF1942AAFA19600513312 /* ConfigurationErrorsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationErrorsView.swift; sourceTree = ""; }; @@ -223,7 +221,7 @@ A5A1F8862A489D7400D1E8BC /* Resources */ = { isa = PBXGroup; children = ( - A545D1A12A5772CE006E0AE4 /* shell-integration */, + 55154BDF2B33911F001622DC /* ghostty */, A5A1F8842A489D6800D1E8BC /* terminfo */, ); name = Resources; @@ -232,7 +230,6 @@ A5B30528299BEAAA0047F10C = { isa = PBXGroup; children = ( - A5CB04372B0F1C1C009ED217 /* themes */, A571AB1C2A206FC600248498 /* Ghostty-Info.plist */, A5B30538299BEAAB0047F10C /* Assets.xcassets */, A5B3053D299BEAAB0047F10C /* Ghostty.entitlements */, @@ -346,9 +343,8 @@ buildActionMask = 2147483647; files = ( A51BFC1E2B2FB5CE00E92F16 /* About.xib in Resources */, - A5CB04382B0F1C1C009ED217 /* themes in Resources */, - A545D1A22A5772CE006E0AE4 /* shell-integration in Resources */, A596309A2AEE1C6400D64628 /* Terminal.xib in Resources */, + 55154BE02B33911F001622DC /* ghostty in Resources */, A5A1F8852A489D6800D1E8BC /* terminfo in Resources */, A5CDF1912AAF9A5800513312 /* ConfigurationErrors.xib in Resources */, A5E112932AF73E6E00C6E0C2 /* ClipboardConfirmation.xib in Resources */, diff --git a/src/os/resourcesdir.zig b/src/os/resourcesdir.zig index a7a6bb367..067c029d2 100644 --- a/src/os/resourcesdir.zig +++ b/src/os/resourcesdir.zig @@ -36,7 +36,7 @@ pub fn resourcesDir(alloc: std.mem.Allocator) !?[]const u8 { // On MacOS, we look for the app bundle path. if (comptime builtin.target.isDarwin()) { if (try maybeDir(&dir_buf, dir, "Contents/Resources", sentinel)) |v| { - return try alloc.dupe(u8, v); + return try std.fs.path.join(alloc, &.{ v, "ghostty" }); } } @@ -44,8 +44,6 @@ pub fn resourcesDir(alloc: std.mem.Allocator) !?[]const u8 { // is valid even on Mac since there is nothing that requires // Ghostty to be in an app bundle. if (try maybeDir(&dir_buf, dir, "share", sentinel)) |v| { - // When found under a "share" prefix, the resources directory is the - // "ghostty" subdirectory. return try std.fs.path.join(alloc, &.{ v, "ghostty" }); } } diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 14cb5a6c7..690cce752 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -762,25 +762,13 @@ const Subprocess = struct { try env.put("TERM", opts.config.term); try env.put("COLORTERM", "truecolor"); + // Assume that the resources directory is adjacent to the terminfo + // database var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - const terminfo_dir = terminfo_dir: { - // On macOS the terminfo directory can be inside the resources - // directory, so check if that is the case - if (comptime builtin.target.isDarwin()) { - if (try internal_os.maybeDir(&buf, base, "terminfo", "ghostty.termcap")) |v| { - break :terminfo_dir v; - } - } - - // Otherwise we assume the terminfo directory is adjacent to the - // resources directory - const parent = std.fs.path.basename(base); - break :terminfo_dir try internal_os.maybeDir(&buf, parent, "terminfo", "ghostty.termcap"); - }; - - if (terminfo_dir) |dir| { - try env.put("TERMINFO", dir); - } + const dir = try std.fmt.bufPrint(&buf, "{s}/terminfo", .{ + std.fs.path.dirname(base) orelse unreachable, + }); + try env.put("TERMINFO", dir); } else { if (comptime builtin.target.isDarwin()) { log.warn("ghostty terminfo not found, using xterm-256color", .{});