Documentation
¶
Overview ¶
Package workspacediff is the shared Diff/Task preview model.
The project Workspaces plugin and the global Workspaces preview both draw the same working-tree + commits view. This package owns snapshot load, first-commit load (short vs full hash), and that render. Neither surface constructs the other.
Index ¶
- Constants
- func CommitDetailMatchesListHash(detail *CommitDetail, listHash string) bool
- func DetectDefaultBranch(ctx context.Context, workdir string) string
- func LoadSnapshotCmd(workdir, baseRef, workspaceID string) tea.Cmd
- func LoadTaskCmd(workDir, taskID, workspaceID string) tea.Cmd
- func RenderTask(tv TaskView, opts TaskRenderOpts) (string, int)
- func TabChips(active Tab) []string
- func TabChipsFor(active Tab, set TabSet) []string
- func TabsVisible(isShell, isMain bool) bool
- type CommitDetail
- type CommitDetailMsg
- type CommitFile
- type CommitInfo
- type File
- type Focus
- type LoadState
- type RenderOpts
- type Scope
- type Snapshot
- type SnapshotMsg
- type Tab
- type TabSet
- type Task
- type TaskMsg
- type TaskRenderOpts
- type TaskView
- type View
- func (v *View) ApplyCommitDetail(msg CommitDetailMsg)
- func (v *View) ApplyLoadedSnapshot(snapshot *Snapshot, workdir, workspaceID string) tea.Cmd
- func (v *View) ApplySnapshot()
- func (v *View) ClampCursor()
- func (v *View) FileCount() int
- func (v *View) LoadSelectedCommit(workdir, workspaceID string) tea.Cmd
- func (v *View) Render(width, height int, opts RenderOpts) string
- func (v *View) ScrollContent(delta int)
- func (v *View) SelectedCommit() (CommitInfo, bool)
- func (v *View) TotalItems() int
- type ViewMode
Constants ¶
const ( RegionDivider = "diff-tab-divider" RegionFile = "diff-tab-file" RegionCommit = "diff-tab-commit" RegionDiffPane = "diff-tab-diff-pane" RegionPreviewFile = "diff-tab-preview-file" RegionFileListPane = "diff-tab-filelist-pane" RegionCommitBack = "commit-file-back" RegionCommitFile = "commit-file-item" RegionCommitDiff = "commit-file-diff-pane" )
const ( MaxUntrackedFileSize = 1 << 20 MaxUntrackedFiles = 50 MaxUntrackedTotalBytes = 4 << 20 )
const CollapseThreshold = 120
CollapseThreshold is the minimum width for the two-pane Diff layout.
Variables ¶
This section is empty.
Functions ¶
func CommitDetailMatchesListHash ¶
func CommitDetailMatchesListHash(detail *CommitDetail, listHash string) bool
CommitDetailMatchesListHash reports whether a loaded commit is the list row. The list stores git %h; detail stores %H in Hash and %h in ShortHash.
func DetectDefaultBranch ¶
DetectDefaultBranch finds the repo's default branch (remote HEAD, then main/master).
func LoadSnapshotCmd ¶
LoadSnapshotCmd loads a snapshot for workdir and tags it with workspaceID.
func LoadTaskCmd ¶
LoadTaskCmd fetches task details from td.
func RenderTask ¶
func RenderTask(tv TaskView, opts TaskRenderOpts) (string, int)
RenderTask draws the linked task, or an empty/loading state. Returns the view and the unclipped line count (for scroll clamping).
func TabChips ¶
TabChips renders the Output / Diff / Task pills. The same chips the project plugin draws, so both surfaces drop whole chips rather than clip one.
func TabChipsFor ¶
TabChipsFor renders only the chips this set allows.
func TabsVisible ¶
TabsVisible reports whether Output / Diff / Task chips belong on a preview: not a shell, and not the main worktree. The project plugin keeps this rule.
Types ¶
type CommitDetail ¶
type CommitDetail struct {
Hash string
ShortHash string
Subject string
Files []CommitFile
}
CommitDetail is the file list for the commit under the cursor.
func LoadCommitDetail ¶
func LoadCommitDetail(ctx context.Context, workdir, hash string) (*CommitDetail, error)
LoadCommitDetail fetches %H/%h/subject and the commit's name-status files.
type CommitDetailMsg ¶
type CommitDetailMsg struct {
WorkspaceID string
Hash string
Commit *CommitDetail
Err error
}
CommitDetailMsg is the result of LoadSelectedCommit.
type CommitFile ¶
CommitFile is one path inside a commit.
type CommitInfo ¶
CommitInfo is one row in the Diff tab commit list. Hash is git %h.
type File ¶
File is one working-tree path in the Diff tab list.
func ParseFiles ¶
ParseFiles splits a unified multi-file diff into named file entries.
type RenderOpts ¶
type RenderOpts struct {
Hit func(id string, x, y, w, h int, data any)
ContentBaseX int
BaseY int
PanelHeight int
Truncate func(string, int, string) string
}
RenderOpts controls optional chrome the project plugin needs and the global preview does not: hit regions, list-pane width.
type Snapshot ¶
type Snapshot struct {
State LoadState
WorkingTree string
Commits []CommitInfo
AggregateCommitted string
AggregateUncommitted string
BaseRef string
MergeBase string
UntrackedShown int
UntrackedOmitted int
UntrackedBytesOmitted int64
Truncated bool
}
Snapshot is the three explicit diff views resolved from one worktree/base identity.
func LoadSnapshot ¶
LoadSnapshot resolves base and HEAD, then loads the pinned snapshot.
type SnapshotMsg ¶
type SnapshotMsg struct {
WorkspaceID string
Snapshot *Snapshot
Err error
Command string
BaseRef string
}
SnapshotMsg is a completed snapshot load for one worktree.
type Tab ¶
type Tab int
Tab is the Output / Diff / Task preview tab.
type TabSet ¶
type TabSet int
TabSet is which preview chips a surface may show.
func GlobalTabsFor ¶
GlobalTabsFor is the global Workspaces chip set: topic worktrees keep all three chips; shells get Output + Diff (no Task); the main worktree stays tabless.
type Task ¶
type Task struct {
ID string
Title string
Status string
Priority string
Type string
Description string
Acceptance string
CreatedAt string
UpdatedAt string
}
Task is the linked-task payload shown on the Task tab.
type TaskRenderOpts ¶
type TaskRenderOpts struct {
// EmptyHint is shown under "No linked task" when TaskID is empty.
// Leave empty on global (that key is not offered).
EmptyHint string
Width int
Height int
Offset int
}
TaskRenderOpts controls the empty-state copy. Global must not offer "t".
type TaskView ¶
type TaskView struct {
TaskID string
Task *Task
Loading bool
Offset int
LineCount int
Error string
}
TaskView is the Task tab model for one worktree.
type View ¶
type View struct {
Snapshot *Snapshot
State LoadState
Error string
Scope Scope
Content string
Raw string
Files []File
Commits []CommitInfo
Cursor int
Scroll int
DiffScroll int
HorizScroll int
Focus Focus
ViewMode ViewMode
CommitDetail *CommitDetail
CommitFileCursor int
CommitFileScroll int
CommitFileDiffRaw string
ListWidth int
}
View is the reusable Diff tab model: one snapshot, one cursor, one commit detail. The project plugin wraps it; the global preview holds one for the selected worktree.
func (*View) ApplyCommitDetail ¶
func (v *View) ApplyCommitDetail(msg CommitDetailMsg)
ApplyCommitDetail installs a loaded commit if it is still the row under the cursor.
func (*View) ApplyLoadedSnapshot ¶
ApplyLoadedSnapshot installs a snapshot, applies the default working-tree scope, and loads the commit under the cursor if that is the current item.
func (*View) ApplySnapshot ¶
func (v *View) ApplySnapshot()
ApplySnapshot rebuilds the working-tree / commits lists from the snapshot and clamps the cursor. It does not load commit detail; callers that just applied a snapshot should also call LoadSelectedCommit.
func (*View) ClampCursor ¶
func (v *View) ClampCursor()
ClampCursor keeps the cursor inside the current item list.
func (*View) LoadSelectedCommit ¶
LoadSelectedCommit loads the commit under the cursor. Snapshot/scope populate can leave the cursor on a commit without a move, so this does not require a cursor-change event. Skip if that commit is already loaded.
func (*View) Render ¶
func (v *View) Render(width, height int, opts RenderOpts) string
Render draws the working-tree + commits Diff view.
func (*View) ScrollContent ¶
ScrollContent moves the visible right-pane (or collapsed) content.
func (*View) SelectedCommit ¶
func (v *View) SelectedCommit() (CommitInfo, bool)
SelectedCommit is the commit under the cursor, if any.
func (*View) TotalItems ¶
TotalItems is files + commits, the navigable left-pane length.