Improves Git's user interface

This commit is contained in:
2026-11-24 16:43:20 +01:00
parent 2887965a9e
commit 28079e80c5
6 changed files with 114 additions and 26 deletions
+16 -7
View File
@@ -2,7 +2,7 @@ import AppKit
import HelderCore
import SwiftUI
/// The message field over Gen. Commit Message, the author, the ⌘↵ hint and the three commit buttons.
/// The message field over the author, the ⌘↵ hint, Gen. Commit Message and the three commit buttons.
struct GitCommitBlock: View {
let model: WorkspaceModel
let store: SourceControlStore
@@ -22,13 +22,17 @@ struct GitCommitBlock: View {
}
.animation(Metrics.colorTransition, value: isFocused)
HStack(spacing: 16) {
GenerateMessageButton(model: model, store: store)
if let author = store.author {
Text(author).typeRole(Typography.path).foregroundStyle(Palette.textMuted).lineLimit(1)
.frame(minWidth: 0)
}
Text("⌘↵ commits").typeRole(Typography.path).foregroundStyle(Palette.text4).fixedSize()
Spacer(minLength: 0)
CommitButtons(model: model, store: store)
HStack(spacing: 8) {
GenerateMessageButton(model: model, store: store)
CommitButtons(model: model, store: store)
}
.layoutPriority(1)
}
.padding(.leading, 16)
.padding(.trailing, 14)
@@ -134,7 +138,7 @@ private struct CommitButtons: View {
}
}
/// Plex Mono 14/1.6 message field that grows with its wrapped text from 56 to 180pt, measured in `sizeThatFits`.
/// Right-aligned Plex Mono 14/1.6 message field that grows with its wrapped text from 56 to 180pt, measured in `sizeThatFits`.
struct GitMessageField: NSViewRepresentable {
let text: String
/// A new value takes first responder once, a run loop later: opening the view clears first responder first.
@@ -172,7 +176,9 @@ struct GitMessageField: NSViewRepresentable {
textView.textContainer?.widthTracksTextView = true
textView.maxSize = NSSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
textView.fillsClipView = true
textView.alignment = .right
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .right
paragraph.minimumLineHeight = role.lineHeight ?? 22.4
paragraph.maximumLineHeight = role.lineHeight ?? 22.4
textView.defaultParagraphStyle = paragraph
@@ -193,6 +199,7 @@ struct GitMessageField: NSViewRepresentable {
static func height(of text: String, width: CGFloat) -> CGFloat {
let role = Typography.commitMessage
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .right
paragraph.minimumLineHeight = role.lineHeight ?? 22.4
paragraph.maximumLineHeight = role.lineHeight ?? 22.4
let storage = NSTextStorage(string: text, attributes: [.font: role.nsFont, .paragraphStyle: paragraph])
@@ -252,7 +259,7 @@ struct GitMessageField: NSViewRepresentable {
}
/// Draws the placeholder and reports focus.
/// Draws the placeholder at the right inset and reports focus.
final class MessageTextView: PointerBoundTextView {
var placeholder = ""
var onFocusChange: ((Bool) -> Void)?
@@ -276,7 +283,9 @@ final class MessageTextView: PointerBoundTextView {
.font: font ?? Typography.commitMessage.nsFont, .foregroundColor: NSColor(hex: 0x6C7783),
.paragraphStyle: defaultParagraphStyle ?? NSParagraphStyle.default,
]
let origin = NSPoint(x: textContainerInset.width + (textContainer?.lineFragmentPadding ?? 0), y: textContainerInset.height)
(placeholder as NSString).draw(at: origin, withAttributes: attributes)
let text = placeholder as NSString
let inset = textContainerInset.width + (textContainer?.lineFragmentPadding ?? 0)
let origin = NSPoint(x: bounds.width - inset - text.size(withAttributes: attributes).width, y: textContainerInset.height)
text.draw(at: origin, withAttributes: attributes)
}
}
@@ -1,7 +1,7 @@
import HelderCore
import SwiftUI
/// The bottom strip's right end on a wide window: the last commits of the current branch, read-only.
/// The last commits of the current branch, read-only: under the branches in the side columns, else the strip's right end.
struct GitCommitsPanel: View {
let store: SourceControlStore
+68 -4
View File
@@ -10,10 +10,17 @@ struct GitView: View {
if let store = model.sourceControl {
VStack(spacing: 0) {
GitTopBar(model: model, store: store)
GitCommitBlock(model: model, store: store)
GitSectionsList(model: model, store: store)
.frame(maxHeight: .infinity)
GitBottomStrip(model: model, store: store)
GeometryReader { proxy in
switch GitBodyMode(width: proxy.size.width) {
case .sideColumns:
GitSideColumns(model: model, store: store, height: proxy.size.height)
case .bottomStrip:
VStack(spacing: 0) {
GitChanges(model: model, store: store)
GitBottomStrip(model: model, store: store)
}
}
}
}
} else {
Color.clear
@@ -25,6 +32,50 @@ struct GitView: View {
}
}
/// The commit block over the sections, filling the height it gets.
private struct GitChanges: View {
let model: WorkspaceModel
let store: SourceControlStore
var body: some View {
VStack(spacing: 0) {
GitCommitBlock(model: model, store: store)
GitSectionsList(model: model, store: store)
.frame(maxHeight: .infinity)
}
}
}
/// Branches over commits on the left, the changes in the middle, the console on the right, all full height.
private struct GitSideColumns: View {
let model: WorkspaceModel
let store: SourceControlStore
let height: CGFloat
var body: some View {
let half = max(0, (height - Metrics.hairline) / 2).rounded(.down)
HStack(spacing: 0) {
VStack(spacing: 0) {
GitBranchesPanel(model: model, store: store)
.frame(height: half)
Hairline()
GitCommitsPanel(store: store)
.frame(maxHeight: .infinity)
}
.frame(width: GitMetrics.sideColumnWidth)
.background(Palette.panel)
.hairline(.trailing)
GitChanges(model: model, store: store)
.frame(maxWidth: .infinity)
GitConsolePanel(model: model, store: store)
.frame(width: GitMetrics.consoleColumnWidth)
.frame(maxHeight: .infinity)
.background(Palette.panel)
.hairline(.leading)
}
}
}
/// The console left, the branches right, 230pt tall; a wide window adds the commit list after them.
private struct GitBottomStrip: View {
let model: WorkspaceModel
@@ -53,6 +104,16 @@ private struct GitBottomStrip: View {
}
}
/// How the body under the top bar is laid out for one window width.
enum GitBodyMode: Equatable {
case sideColumns
case bottomStrip
init(width: CGFloat) {
self = width >= GitMetrics.sideColumnsMinWidth ? .sideColumns : .bottomStrip
}
}
/// The widths of the bottom strip's panels for one strip width.
struct GitStripLayout: Equatable {
var console: CGFloat
@@ -97,6 +158,9 @@ enum GitMetrics {
static let consoleMaxWidth: CGFloat = 820
static let branchesMaxWidth: CGFloat = 820
static let commitsMinWidth: CGFloat = 260
static let sideColumnsMinWidth: CGFloat = 1600
static let sideColumnWidth: CGFloat = 480
static let consoleColumnWidth: CGFloat = 560
static let stripHeader: CGFloat = 32
static let branchRow: CGFloat = 28
}
@@ -3,6 +3,17 @@ import CoreGraphics
import Testing
@Suite struct GitStripLayoutTests {
@Test func belowTheBreakpointTheBodyKeepsTheBottomStrip() {
#expect(GitBodyMode(width: 1599) == .bottomStrip)
#expect(GitBodyMode(width: 1024) == .bottomStrip)
}
@Test func fromTheBreakpointTheBodyUsesSideColumns() {
#expect(GitBodyMode(width: GitMetrics.sideColumnsMinWidth) == .sideColumns)
#expect(GitBodyMode(width: 1600) == .sideColumns)
#expect(GitBodyMode(width: 2560) == .sideColumns)
}
@Test func aNarrowStripSplitsEvenlyWithoutTheCommitList() {
let layout = GitStripLayout(width: 1201)
#expect(layout.console == 600)
+9 -7
View File
@@ -69,13 +69,13 @@ From top to bottom:
- Background `#18202B`, bottom border `1px #232C39`.
- **Message textarea**: full width, auto-grows (`field-sizing: content`) from 56px up to 180px.
- Background `#101720`, no border except a `1px #232C39` bottom border, which turns `#E8913A` on focus.
- Padding `14px 16px`, Plex Mono 400, 14px / 1.6, colour `#F4F5F4`, caret `#E8913A`.
- Placeholder: `Commit message`. The field gets focus when the Git view opens.
- **Footer row**: 52px tall, padding `0 14px 0 16px`, gap 16px.
- **Gen. Commit Message** (small secondary), first on the left: 32px tall, padding `0 12px`, radius 2px, a `1px #232C39` border, the pass-on spark glyph (12px, stroke) then the label in the commit-button type, text `#BAC0C0`; hover fills `#1E2733` and turns glyph and text `#F4F5F4`. While it runs the label reads `Generating…`. Disabled (40% opacity, default cursor, no clicks) when nothing is staged or while it runs. A click sends the staged diff to the Claude CLI and puts its one-line answer in the message field (replacing the draft, lowercased like typed text) and focuses the field; a failure toasts `Couldn't generate a commit message` with the reason (`claude not found`, the CLI's first error line, `timed out`). Native build only.
- Author `Jonathan van Rij <jonathan@blijnder.nl>` in Plex Mono 12px `#828D9A`. In the real build, read this from `git config user.name` and `user.email`.
- Padding `14px 16px`, Plex Mono 400, 14px / 1.6, colour `#F4F5F4`, caret `#E8913A`, text right-aligned.
- Placeholder: `Commit message`, right-aligned. The field gets focus when the Git view opens.
- **Footer row**: 52px tall, padding `0 14px 0 16px`, gap 16px. Order: author, hint, a spacer, then Gen. Commit Message and the three commit buttons, gap 8px.
- **Gen. Commit Message** (small secondary), on the right just before Add, Stage & Commit: 32px tall, padding `0 12px`, radius 2px, a `1px #232C39` border, the pass-on spark glyph (12px, stroke) then the label in the commit-button type, text `#BAC0C0`; hover fills `#1E2733` and turns glyph and text `#F4F5F4`. While it runs the label reads `Generating…`. Disabled (40% opacity, default cursor, no clicks) when nothing is staged or while it runs. A click sends the staged diff to the Claude CLI and puts its one-line answer in the message field (replacing the draft, lowercased like typed text) and focuses the field; a failure toasts `Couldn't generate a commit message` with the reason (`claude not found`, the CLI's first error line, `timed out`). Native build only.
- Author `Jonathan van Rij <jonathan@blijnder.nl>` in Plex Mono 12px `#828D9A`, first on the left; it truncates when space runs out. In the real build, read this from `git config user.name` and `user.email`.
- Hint `⌘↵ commits` in Plex Mono 12px `#6C7783`.
- A spacer, then **three buttons** side by side, gap 8px, each radius 2px, 32px tall, padding `0 18px`, Plex Sans 600 13px:
- A spacer, then Gen. Commit Message and **three buttons** side by side, gap 8px, each radius 2px, 32px tall, padding `0 18px`, Plex Sans 600 13px:
- **Add, Stage & Commit** (secondary), on the left: the same look as Commit. Stages every unstaged path with `git add -- <paths>`, then commits without a push. An empty message stages nothing and focuses the message field. Disabled (40% opacity, default cursor, no clicks) with no changes, during a merge conflict, or while a push or pull runs.
- **Commit** (secondary): min-width 160px, label `Commit N file(s)`, or `Nothing staged` when nothing is staged. Transparent with a `1px #232C39` border and text `#BAC0C0`; hover fills `#1E2733` and turns the text `#F4F5F4`.
- **Commit and push** (primary), on the right. Ready state (≥1 staged file **and** a non-empty message): background `#E8913A`, text `#101720`, hover amber-deep `#C4741F`. Otherwise: background `#232C39`, text `#828D9A`, hover `#202834`. With files staged it stays clickable, so git's own error appears in the console.
@@ -149,7 +149,9 @@ If there are no changes at all, the area shows only: `— No changes. The workin
- Added files show everything on the right; deleted files show everything on the left.
- The prototype uses an LCS line diff (`diffOps`). In production, use `git diff` hunks (`--unified=3`), or a proper diff library, and pair `-`/`+` runs line by line.
### 5. Bottom strip — 230px, split 50/50
### 5. Bottom strip — 230px, split 50/50 (side columns from 1600px)
- **Window ≥ 1600px** (native build only): no strip. Under the top bar three full-height columns: left 480px with branches over commits (half the height each, a `1px #232C39` line between, a `1px #232C39` right border), the commit block and sections in the middle, the console right at 560px (`1px #232C39` left border). Both side columns have background `#18202B`.
- **Narrower**: the strip below, as follows.
- Background `#18202B`, top border `1px #232C39`.
- `display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr)`. The left half has a `1px #232C39` right border.
- Native build: console and branches each stop at 820px. When at least 260px is left after them, a **commits** list fills the rest behind a `1px #232C39` left border; below that the rest stays empty. Not in the prototype.
+9 -7
View File
@@ -62,13 +62,13 @@ Opening the view reads the author and the branches, re-reads git and runs `git f
### Commit block
- The **commit message**: always one lowercase line. Capitals become lowercase and line breaks become spaces as the user types or pastes, so `Enter` never starts a second line. The field grows with wrapped text from 56 to 180 points. An amber underline shows focus.
- **Gen. Commit Message**, a small secondary button with the pass-on spark, first on the left of the footer. It asks the Claude CLI for a message for the **staged** changes and puts the answer in the message field, replacing the draft, then focuses the field. The answer goes through the same one-lowercase-line rule as typed text.
- The **commit message**: always one lowercase line. Capitals become lowercase and line breaks become spaces as the user types or pastes, so `Enter` never starts a second line. The field grows with wrapped text from 56 to 180 points. The text and the `Commit message` placeholder are right-aligned. An amber underline shows focus.
- **Gen. Commit Message**, a small secondary button with the pass-on spark, on the right of the footer just before **Add, Stage & Commit**. It asks the Claude CLI for a message for the **staged** changes and puts the answer in the message field, replacing the draft, then focuses the field. The answer goes through the same one-lowercase-line rule as typed text.
- The prompt holds the writing rules (one sentence, no quotes, no prefix, no body, English, a verb in the third person or past tense, two separate changes joined with ` - `), three example messages, `git diff --cached --stat` in full and `git diff --cached` cut after 60 000 characters (the prompt says when it is cut).
- It runs `claude -p --output-format text --no-session-persistence --strict-mcp-config --disable-slash-commands --tools ""` with the prompt on stdin, in the project root, with the CLI's default model and no tools; `claude` is looked up on PATH, Homebrew, `~/.local/bin` and `~/.claude/local`. The run times out after 90 seconds. The first non-empty line of the answer, without surrounding quotes or backticks, becomes the message.
- While it runs the label reads `Generating…` and a second click is ignored. It is disabled (dimmed, arrow cursor) when nothing is staged or while it runs.
- A failure leaves the draft alone and toasts `Couldn't generate a commit message` with the reason: `claude not found`, the CLI's first error line, or `timed out`.
- The **author**, `user.name <user.email>` from git config.
- The **author**, `user.name <user.email>` from git config, first on the left; it truncates when space runs out.
- A `⌘↵ commits` hint.
- Three buttons side by side: **Add, Stage & Commit** and **Commit** (`Commit N files`, or `Nothing staged`), both secondary buttons with a hairline border, and **Commit and push**, the primary one. Commit and push is amber when something is staged and the message is not empty, grey otherwise. With nothing staged Commit and Commit and push are disabled: dimmed, the arrow pointer, and a click does nothing.
- **Add, Stage & Commit** stages every unstaged path (edits, deletions and new files) with `git add -- <paths>`, then commits as **Commit** does, without a push. With an empty message it stages nothing, runs no git, and the message field takes the focus. It is disabled when there are no changes at all, during a merge conflict (staging a conflicted file marks it resolved), and while a push or pull runs. When `git add` fails, no commit runs.
@@ -92,21 +92,23 @@ Four colour-coded sections, each only when it has rows, in this order:
### Bottom strip
230pt tall: the console left, the branches right, sharing the width equally up to 820pt each. When the room left over is at least 260pt, the **commits** list fills it, after a hairline; otherwise that room stays empty.
From a window 1600pt wide there is no strip: under the top bar three full-height columns, the **branches** over the **commits** on the left (480pt, half the height each, a hairline between), the commit block and sections in the middle, the **console** on the right (560pt). Hairlines separate the columns.
Narrower, a 230pt strip under the sections: the console left, the branches right, sharing the width equally up to 820pt each. When the room left over is at least 260pt, the **commits** list fills it, after a hairline; otherwise that room stays empty.
### Console
The bottom-left panel. Every action logs the exact git command (`$ git add -- path`) and streams its output line by line, coloured by kind: errors, hints, staged and unstaged lines of `status`, and the ref update of a push. Below the log, a `$ git` input runs typed commands, with or without a leading `git`. `clear` empties the log, a bare `log` runs `log --oneline --decorate -n 30`, and `Up` recalls earlier input. Commands, typed or from buttons, run one at a time. The log keeps the last 400 lines.
The bottom-left panel, or the right column from 1600pt. Every action logs the exact git command (`$ git add -- path`) and streams its output line by line, coloured by kind: errors, hints, staged and unstaged lines of `status`, and the ref update of a push. Below the log, a `$ git` input runs typed commands, with or without a leading `git`. `clear` empties the log, a bare `log` runs `log --oneline --decorate -n 30`, and `Up` recalls earlier input. Commands, typed or from buttons, run one at a time. The log keeps the last 400 lines.
### Branches
The bottom-right panel: **local** branches, then **remote · origin**. The current branch is marked; a remote branch with a local counterpart reads `tracked`. A click switches (`switch →`); a remote branch without a local one is checked out as a new tracking branch (`checkout →`). While there are uncommitted changes, switching is locked: the header says so, the other branches dim, and a click shows a toast instead of running git.
The bottom-right panel, or the top of the left column from 1600pt: **local** branches, then **remote · origin**. The current branch is marked; a remote branch with a local counterpart reads `tracked`. A click switches (`switch →`); a remote branch without a local one is checked out as a new tracking branch (`checkout →`). While there are uncommitted changes, switching is locked: the header says so, the other branches dim, and a click shows a toast instead of running git.
**Right-click** a branch other than the current one: the menu, headed by the branch name, has one item, **Merge into <current>**, which runs `git merge --no-edit <branch>` (local and `origin/` branches alike). With uncommitted changes the item is disabled: dimmed, with the arrow and the tooltip `Commit or discard your changes first`; `Up`/`Down` skip it and a click does nothing. The current branch opens no menu. The merge always asks first, `Merge <branch> into <current>?`, and runs only on **Merge**. A merge that stops on conflicts says `Merge conflict — resolve, then commit`.
### Commits
The bottom strip's right end on a wide window, headed `[ commits ]` with the current branch muted on the right. A scrolling list of the last 30 commits of the current branch (HEAD), newest first, one row each: the short hash (amber), the subject on one line, and right-aligned `author · 3 h ago`. The relative time ticks along. Rows are read-only: no click, no hover, the arrow cursor. A repository without commits reads `no commits yet`; outside a repository `— no repository`.
Under the branches in the left column from 1600pt; narrower, the bottom strip's right end when there is room. Headed `[ commits ]` with the current branch muted on the right. A scrolling list of the last 30 commits of the current branch (HEAD), newest first, one row each: the short hash (amber), the subject on one line, and right-aligned `author · 3 h ago`. The relative time ticks along. Rows are read-only: no click, no hover, the arrow cursor. A repository without commits reads `no commits yet`; outside a repository `— no repository`.
The list is read when the view opens and after every command, with the branches.