adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
+30 -15
View File
@@ -7,8 +7,10 @@ public enum ContextTarget: Sendable, Equatable {
case editor(reference: AgentReference, code: String?, showDiffLine: Int? = nil)
case file(path: String)
case directory(path: String)
/// A git row; the row carries its own half, since one file can have two rows.
case gitRow(path: String, staged: Bool)
/// A file row in the Git view; a deleted file has nothing to open.
case gitRow(path: String, isDeleted: Bool)
/// The caret beside the Git view's Commit button.
case commitMenu
/// The empty space under the tree: the project folder itself.
case projectRoot
case terminal(TerminalKind, hasSelection: Bool)
@@ -17,7 +19,7 @@ public enum ContextTarget: Sendable, Equatable {
switch self {
case let .editor(reference, _, _): reference.path
case let .file(path), let .directory(path), let .gitRow(path, _): path
case .projectRoot, .terminal: ""
case .projectRoot, .terminal, .commitMenu: ""
}
}
}
@@ -30,12 +32,13 @@ public enum ContextAction: Sendable, Equatable {
case copyFileName(String)
case newFile(inDirectory: String)
case newFolder(inDirectory: String)
case stage(String)
case unstage(String)
case openDiff(String)
/// Opens a file from the Git view, which closes first.
case openFile(String)
/// Reverts unstaged changes: modified and deleted files come back from the index, new files are removed.
case gitDiscard([String])
case commit(andPush: Bool)
/// Opens the Diff of the open file at this line.
case showDiff(String, line: Int)
case discard(String)
case rename(String, isDirectory: Bool)
case revealInFinder(String)
case delete(String, isDirectory: Bool)
@@ -58,7 +61,15 @@ public enum ContextAction: Sendable, Equatable {
/// Destructive items read in amber-deep.
public var isDestructive: Bool {
switch self {
case .discard, .delete: true
case .gitDiscard, .delete: true
default: false
}
}
/// The menu's main item, set in bold.
public var isEmphasized: Bool {
switch self {
case .openFile, .commit(andPush: true): true
default: false
}
}
@@ -76,7 +87,7 @@ public enum ContextActions {
switch target {
case let .file(path), let .gitRow(path, _): path
case .projectRoot: projectName + "/"
case .editor, .directory, .terminal: ""
case .editor, .directory, .terminal, .commitMenu: ""
}
}
@@ -127,12 +138,16 @@ public enum ContextActions {
? [.separator, .action(.waitWhat(kind), label: "Wait what?")] : []
return (hasSelection ? [.action(.copyTerminalSelection(kind), label: "Copy")] : [])
+ [.action(.pasteIntoTerminal(kind), label: "Paste")] + readAloud + waitWhat
case let .gitRow(path, staged):
return fileHead(path) + readAloudFile(path) + [
.separator,
staged ? .action(.unstage(path), label: "Unstage changes") : .action(.stage(path), label: "Stage changes"),
.action(.openDiff(path), label: "Open diff"),
.action(.discard(path), label: "Discard changes"),
case let .gitRow(path, isDeleted):
let open: [ContextMenuEntry] = isDeleted ? [] : [.action(.openFile(path), label: "Open in editor"), .separator]
return open + [
.action(.passOnReference(path, code: nil), label: "Pass on reference"),
.action(.copyReference(path), label: "Copy reference"),
]
case .commitMenu:
return [
.action(.commit(andPush: false), label: "Commit"),
.action(.commit(andPush: true), label: "Commit and push"),
]
}
}