Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cb0767b
Expose file explorer git colors through config
austinywang May 12, 2026
f5ff98a
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 12, 2026
f03816c
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 12, 2026
d208d19
Avoid render-path git status preference reads
austinywang May 12, 2026
dce2c5d
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 12, 2026
ceb09f8
Fix file explorer git color cache refresh
austinywang May 12, 2026
6c38851
Avoid unrelated git color cache reloads
austinywang May 12, 2026
edc3868
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 12, 2026
4e979f9
Refactor file explorer git status colors
austinywang May 12, 2026
95c68d9
Harden file explorer git color parsing
austinywang May 12, 2026
f4944c3
Clarify git color cache test warmup
austinywang May 12, 2026
93d3a5d
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 12, 2026
fbb6463
Fix file explorer git color actor isolation
austinywang May 12, 2026
f4f9e59
Fix file explorer git color notification isolation
austinywang May 12, 2026
6941e95
Fix git color cache reload ordering
austinywang May 12, 2026
bba8295
Fix git status color cache ownership
austinywang May 12, 2026
098c2c2
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 13, 2026
925c342
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 14, 2026
7bc332d
fix: address file explorer git color review
austinywang May 14, 2026
1f9b23b
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 18, 2026
304d86b
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 18, 2026
109dc4e
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang May 19, 2026
45fb8a6
Merge remote-tracking branch 'origin/main' into issue-3848-file-explo…
austinywang May 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GhosttyTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
FA000000A1B2C3D4E5F60718 /* WorkspaceStressProfileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA000001A1B2C3D4E5F60718 /* WorkspaceStressProfileTests.swift */; };
FA100000A1B2C3D4E5F60718 /* BrowserImportMappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA100001A1B2C3D4E5F60718 /* BrowserImportMappingTests.swift */; };
FB100000A1B2C3D4E5F60718 /* BrowserImportProfilesUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB100001A1B2C3D4E5F60718 /* BrowserImportProfilesUITests.swift */; };
FE001105 /* FileExplorerGitStatusColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE001005 /* FileExplorerGitStatusColors.swift */; };
FE001101 /* FileExplorerStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE001001 /* FileExplorerStore.swift */; };
B37A00000000000000000009 /* FileExplorerState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B37A0000000000000000000A /* FileExplorerState.swift */; };
FE001102 /* FileExplorerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE001002 /* FileExplorerView.swift */; };
Expand Down Expand Up @@ -907,6 +908,7 @@
FA000001A1B2C3D4E5F60718 /* WorkspaceStressProfileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceStressProfileTests.swift; sourceTree = "<group>"; };
FA100001A1B2C3D4E5F60718 /* BrowserImportMappingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserImportMappingTests.swift; sourceTree = "<group>"; };
FB100001A1B2C3D4E5F60718 /* BrowserImportProfilesUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserImportProfilesUITests.swift; sourceTree = "<group>"; };
FE001005 /* FileExplorerGitStatusColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExplorerGitStatusColors.swift; sourceTree = "<group>"; };
FE001001 /* FileExplorerStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExplorerStore.swift; sourceTree = "<group>"; };
B37A0000000000000000000A /* FileExplorerState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExplorerState.swift; sourceTree = "<group>"; };
FE001002 /* FileExplorerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExplorerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1294,6 +1296,7 @@
E30750000000000000000003 /* CmuxWorkspaceDefinition.swift */,
A5001653 /* CmuxConfigExecutor.swift */,
A5001655 /* CmuxActionTrust.swift */,
FE001005 /* FileExplorerGitStatusColors.swift */,
FE001001 /* FileExplorerStore.swift */,
B37A0000000000000000000A /* FileExplorerState.swift */,
FE001003 /* FileExplorerSearchController.swift */,
Expand Down Expand Up @@ -1933,6 +1936,7 @@
E30750000000000000000004 /* CmuxWorkspaceDefinition.swift in Sources */,
A5001652 /* CmuxConfigExecutor.swift in Sources */,
A5001654 /* CmuxActionTrust.swift in Sources */,
FE001105 /* FileExplorerGitStatusColors.swift in Sources */,
FE001101 /* FileExplorerStore.swift in Sources */,
B37A00000000000000000009 /* FileExplorerState.swift in Sources */,
FE001103 /* FileExplorerSearchController.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Sources/CmuxSettingsJSONPathSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extension CmuxSettingsFileStore {
"sidebar.showLog",
"sidebar.showProgress",
"sidebar.showCustomMetadata",
"fileExplorer.gitStatusColors",
"workspaceColors.indicatorStyle",
"workspaceColors.selectionColor",
"workspaceColors.notificationBadgeColor",
Expand Down
88 changes: 88 additions & 0 deletions Sources/FileExplorerGitStatusColors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import AppKit
import Foundation

enum FileExplorerGitStatusColorSettings {
static let userDefaultsKey = "fileExplorer.gitStatusColors"

static func normalizedStatusName(_ rawName: String) -> String? {
let name = rawName.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
guard GitFileStatus(rawValue: name) != nil else { return nil }
return name
}

@MainActor
static func resolvedColor(
for status: GitFileStatus,
fallback: NSColor,
defaults: UserDefaults = .standard
) -> NSColor {
FileExplorerGitStatusColorPalette.shared.color(for: status, fallback: fallback, defaults: defaults)
}
}

@MainActor
private final class FileExplorerGitStatusColorPalette {
static let shared = FileExplorerGitStatusColorPalette()

private let defaults: UserDefaults
private let notificationCenter: NotificationCenter
private var colorsByStatus: [String: NSColor] = [:]
private var styleObserver: NSObjectProtocol?

init(
defaults: UserDefaults = .standard,
notificationCenter: NotificationCenter = .default
) {
self.defaults = defaults
self.notificationCenter = notificationCenter
reload()
styleObserver = notificationCenter.addObserver(
forName: .fileExplorerStyleDidChange,
object: nil,
queue: nil
) { [weak self] _ in
MainActor.assumeIsolated {
self?.reload()
}
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

deinit {
if let styleObserver {
notificationCenter.removeObserver(styleObserver)
}
}
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved

func color(
for status: GitFileStatus,
fallback: NSColor,
defaults requestedDefaults: UserDefaults
) -> NSColor {
guard requestedDefaults === defaults else {
return Self.loadedColors(from: requestedDefaults)[status.rawValue] ?? fallback
}
let color = colorsByStatus[status.rawValue]
return color ?? fallback
}

private func reload() {
let colors = Self.loadedColors(from: defaults)
colorsByStatus = colors
}

private static func loadedColors(from defaults: UserDefaults) -> [String: NSColor] {
guard let colors = defaults.dictionary(
forKey: FileExplorerGitStatusColorSettings.userDefaultsKey
) else {
return [:]
}
return colors.reduce(into: [:]) { result, pair in
guard let hex = pair.value as? String,
let status = FileExplorerGitStatusColorSettings.normalizedStatusName(pair.key),
let color = NSColor(hex: hex) else {
return
}
result[status] = color
}
}
}
10 changes: 9 additions & 1 deletion Sources/FileExplorerStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ enum FileExplorerStyle: Int, CaseIterable {
}
}

@MainActor
func gitColor(for status: GitFileStatus) -> NSColor {
FileExplorerGitStatusColorSettings.resolvedColor(
for: status,
fallback: defaultGitColor(for: status)
)
}

private func defaultGitColor(for status: GitFileStatus) -> NSColor {
switch self {
case .liquidGlass:
switch status {
Expand Down Expand Up @@ -1155,7 +1163,7 @@ final class FileExplorerDirectoryWatcher {

// MARK: - Git Status

enum GitFileStatus {
enum GitFileStatus: String, CaseIterable {
case modified, added, deleted, renamed, untracked
}

Expand Down
11 changes: 11 additions & 0 deletions Sources/KeyboardShortcutSettingsFileStore+Template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ extension CmuxSettingsFileStore {
),
],
],
[
"fileExplorer": [
"gitStatusColors": [
"modified": "#218D8F",
"added": "#2AA54D",
"deleted": "#D24545",
"renamed": "#7C68EF",
"untracked": "#577172",
],
],
],
[
"sidebarAppearance": [
"matchTerminalBackground": false,
Expand Down
41 changes: 41 additions & 0 deletions Sources/KeyboardShortcutSettingsFileStore.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Combine
import Foundation
import os

@MainActor
final class KeyboardShortcutSettingsObserver: ObservableObject {
Expand All @@ -19,6 +20,8 @@ final class KeyboardShortcutSettingsObserver: ObservableObject {
final class CmuxSettingsFileStore {
static let shared = CmuxSettingsFileStore()

private static let logger = Logger(subsystem: "com.cmuxterm.app", category: "CmuxSettingsFileStore")

static let currentSchemaVersion = 1
static let schemaURLString = "https://raw.githubusercontent.com/manaflow-ai/cmux/main/web/data/cmux.schema.json"
private static let legacySchemaURLString = "https://raw.githubusercontent.com/manaflow-ai/cmux/main/web/data/cmux-settings.schema.json"
Expand Down Expand Up @@ -317,6 +320,9 @@ final class CmuxSettingsFileStore {
if let sidebarSection = root["sidebar"] as? [String: Any] {
parseSidebarSection(sidebarSection, sourcePath: sourcePath, snapshot: &snapshot)
}
if let fileExplorerSection = root["fileExplorer"] as? [String: Any] {
parseFileExplorerSection(fileExplorerSection, sourcePath: sourcePath, snapshot: &snapshot)
}
if let workspaceColorsSection = root["workspaceColors"] as? [String: Any] {
parseWorkspaceColorsSection(workspaceColorsSection, sourcePath: sourcePath, snapshot: &snapshot)
}
Expand Down Expand Up @@ -611,6 +617,37 @@ final class CmuxSettingsFileStore {
}
}

private func parseFileExplorerSection(
_ section: [String: Any],
sourcePath: String,
snapshot: inout ResolvedSettingsSnapshot
) {
guard section.keys.contains("gitStatusColors") else { return }
guard let rawColors = section["gitStatusColors"] as? [String: Any] else {
logInvalid("fileExplorer.gitStatusColors", sourcePath: sourcePath)
return
}

var normalizedColors: [String: String] = [:]
for (rawStatus, rawValue) in rawColors {
guard let status = FileExplorerGitStatusColorSettings.normalizedStatusName(rawStatus) else {
Self.logger.warning(
"Ignoring unknown file explorer git status '\(rawStatus, privacy: .public)' in \(sourcePath, privacy: .public)"
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
continue
}
guard let rawHex = jsonString(rawValue),
let hex = WorkspaceTabColorSettings.normalizedHex(rawHex) else {
Self.logger.warning(
"Ignoring invalid file explorer git status color '\(rawStatus, privacy: .public)' in \(sourcePath, privacy: .public)"
)
continue
}
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
normalizedColors[status] = hex
}
snapshot.managedUserDefaults[FileExplorerGitStatusColorSettings.userDefaultsKey] = .stringDictionary(normalizedColors)
}

private func parseSidebarAppearanceSection(
_ section: [String: Any],
sourcePath: String,
Expand Down Expand Up @@ -1197,10 +1234,14 @@ final class CmuxSettingsFileStore {
let shouldApplyAppearance = defaultsKey == AppearanceSettings.appearanceModeKey
let appearanceRawValue = shouldApplyAppearance ? UserDefaults.standard.string(forKey: defaultsKey) : nil
let appIconMode = defaultsKey == AppIconSettings.modeKey ? AppIconSettings.resolvedMode() : nil
let notifyFileExplorerAppearance = defaultsKey == FileExplorerGitStatusColorSettings.userDefaultsKey
let apply = {
if notifyScrollBar {
TerminalScrollBarSettings.notifyDidChange(notificationCenter: notificationCenter)
}
if notifyFileExplorerAppearance {
notificationCenter.post(name: .fileExplorerStyleDidChange, object: nil)
}

if let language {
LanguageSettings.apply(language)
Expand Down
105 changes: 105 additions & 0 deletions cmuxTests/KeyboardShortcutSettingsFileStoreStartupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,111 @@ final class KeyboardShortcutSettingsFileStoreStartupTests: XCTestCase {
XCTAssertEqual(defaults.object(forKey: key) as? Bool, false)
}

@MainActor
func testSettingsFileStoreAppliesFileExplorerGitStatusColors() throws {
let defaults = UserDefaults.standard
let key = FileExplorerGitStatusColorSettings.userDefaultsKey
defer { NotificationCenter.default.post(name: .fileExplorerStyleDidChange, object: nil) }

try preservingDefaults(keys: [key, settingsFileBackupsDefaultsKey, importedManagedDefaultsKey]) {
defaults.removeObject(forKey: key)
defaults.removeObject(forKey: settingsFileBackupsDefaultsKey)
defaults.removeObject(forKey: importedManagedDefaultsKey)
// Warm FileExplorerGitStatusColorPalette.shared through
// FileExplorerStyle.highDensity.gitColor(for: .modified); the
// assertions below verify the managed override reloads the cache.
_ = FileExplorerStyle.highDensity.gitColor(for: .modified)
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved

let directoryURL = try makeTemporaryDirectory()
defer { try? FileManager.default.removeItem(at: directoryURL) }

let settingsFileURL = directoryURL.appendingPathComponent("cmux.json", isDirectory: false)
try writeSettingsFile(
"""
{
"fileExplorer": {
"gitStatusColors": {
"modified": "#218d8f",
"added": "#2aa54d",
"deleted": "#d24545",
"renamed": "#7c68ef",
"untracked": "#577172"
}
}
}
""",
to: settingsFileURL
)

_ = KeyboardShortcutSettingsFileStore(
primaryPath: settingsFileURL.path,
fallbackPath: nil,
additionalFallbackPaths: [],
startWatching: false
)

XCTAssertEqual(
defaults.dictionary(forKey: key) as? [String: String],
[
"modified": "#218D8F",
"added": "#2AA54D",
"deleted": "#D24545",
"renamed": "#7C68EF",
"untracked": "#577172",
]
)
XCTAssertEqual(FileExplorerStyle.highDensity.gitColor(for: .modified).hexString(), "#218D8F")
XCTAssertEqual(FileExplorerStyle.highDensity.gitColor(for: .added).hexString(), "#2AA54D")
XCTAssertEqual(FileExplorerStyle.highDensity.gitColor(for: .deleted).hexString(), "#D24545")
XCTAssertEqual(FileExplorerStyle.highDensity.gitColor(for: .renamed).hexString(), "#7C68EF")
XCTAssertEqual(FileExplorerStyle.highDensity.gitColor(for: .untracked).hexString(), "#577172")
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
}
}

@MainActor
func testFileExplorerGitStatusColorsIgnoreMalformedPersistedEntries() throws {
let suiteName = "cmux-file-explorer-git-colors-\(UUID().uuidString)"
let defaults = try XCTUnwrap(UserDefaults(suiteName: suiteName))
defer { defaults.removePersistentDomain(forName: suiteName) }

defaults.set(
[
"modified": "#123456",
"added": 12,
"deleted": "not-a-color",
"unknown": "#FFFFFF",
],
forKey: FileExplorerGitStatusColorSettings.userDefaultsKey
)
let addedFallback = try XCTUnwrap(NSColor(hex: "#00AA00"))
let deletedFallback = try XCTUnwrap(NSColor(hex: "#AA0000"))

XCTAssertEqual(
FileExplorerGitStatusColorSettings.resolvedColor(
for: .modified,
fallback: .systemOrange,
defaults: defaults
).hexString(),
"#123456"
)
XCTAssertEqual(
FileExplorerGitStatusColorSettings.resolvedColor(
for: .added,
fallback: addedFallback,
defaults: defaults
).hexString(),
"#00AA00"
)
XCTAssertEqual(
FileExplorerGitStatusColorSettings.resolvedColor(
for: .deleted,
fallback: deletedFallback,
defaults: defaults
).hexString(),
"#AA0000"
)
}

private func makeTemporaryDirectory() throws -> URL {
let url = FileManager.default.temporaryDirectory.appendingPathComponent(
"cmux-settings-startup-\(UUID().uuidString)",
Expand Down
Loading
Loading