workspacediff

package
v0.98.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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"
)
View Source
const (
	MaxUntrackedFileSize   = 1 << 20
	MaxUntrackedFiles      = 50
	MaxUntrackedTotalBytes = 4 << 20
)
View Source
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

func DetectDefaultBranch(ctx context.Context, workdir string) string

DetectDefaultBranch finds the repo's default branch (remote HEAD, then main/master).

func LoadSnapshotCmd

func LoadSnapshotCmd(workdir, baseRef, workspaceID string) tea.Cmd

LoadSnapshotCmd loads a snapshot for workdir and tags it with workspaceID.

func LoadTaskCmd

func LoadTaskCmd(workDir, taskID, workspaceID string) tea.Cmd

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

func TabChips(active Tab) []string

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

func TabChipsFor(active Tab, set TabSet) []string

TabChipsFor renders only the chips this set allows.

func TabsVisible

func TabsVisible(isShell, isMain bool) bool

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

type CommitFile struct {
	Path      string
	Status    string
	Additions int
	Deletions int
}

CommitFile is one path inside a commit.

type CommitInfo

type CommitInfo struct {
	Hash    string
	Subject string
	Pushed  bool
	Merged  bool
}

CommitInfo is one row in the Diff tab commit list. Hash is git %h.

type File

type File struct {
	Path      string
	Raw       string
	Additions int
	Deletions int
}

File is one working-tree path in the Diff tab list.

func ParseFiles

func ParseFiles(raw string) []File

ParseFiles splits a unified multi-file diff into named file entries.

type Focus

type Focus int

Focus is which sub-pane of the Diff tab is active.

const (
	FocusFileList Focus = iota
	FocusDiff
	FocusCommitFiles
	FocusCommitDiff
)

type LoadState

type LoadState int

LoadState is the snapshot / view load lifecycle.

const (
	LoadStateUnknown LoadState = iota
	LoadStateLoading
	LoadStateClean
	LoadStateReady
	LoadStateTruncated
	LoadStateError
)

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 Scope

type Scope int

Scope names the three distinct questions answered by the Diff tab.

const (
	ScopeWorkingTree Scope = iota
	ScopeCommits
	ScopeAggregate
)

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

func LoadSnapshot(ctx context.Context, workdir, baseRef string) (*Snapshot, error)

LoadSnapshot resolves base and HEAD, then loads the pinned snapshot.

func LoadSnapshotPinned

func LoadSnapshotPinned(ctx context.Context, workdir, baseRef, baseOID, headOID string) (*Snapshot, error)

LoadSnapshotPinned loads working-tree, unique commits, and aggregate diffs against already-resolved OIDs.

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.

const (
	TabOutput Tab = iota
	TabDiff
	TabTask
)

func CycleTab

func CycleTab(current Tab, delta int) Tab

CycleTab walks Output → Diff → Task (or the reverse) for a topic worktree.

func CycleTabIn

func CycleTabIn(current Tab, delta int, set TabSet) Tab

CycleTabIn walks only the tabs this set allows.

type TabSet

type TabSet int

TabSet is which preview chips a surface may show.

const (
	// TabSetNone is shells (project plugin) and the main worktree.
	TabSetNone TabSet = iota
	// TabSetOutputDiffTask is a topic worktree: Output / Diff / Task.
	TabSetOutputDiffTask
	// TabSetOutputDiff is a global shell: Output / Diff, no Task.
	TabSetOutputDiff
)

func GlobalTabsFor

func GlobalTabsFor(isShell, isMain bool) TabSet

GlobalTabsFor is the global Workspaces chip set: topic worktrees keep all three chips; shells get Output + Diff (no Task); the main worktree stays tabless.

func TabsFor

func TabsFor(isShell, isMain bool) TabSet

TabsFor is the project-plugin chip set: topic worktrees only.

func (TabSet) Contains

func (s TabSet) Contains(tab Tab) bool

Contains reports that tab is in this set.

func (TabSet) Tabs

func (s TabSet) Tabs() []Tab

Tabs is the allowed tabs in cycle order.

func (TabSet) Visible

func (s TabSet) Visible() bool

Visible reports that this set draws a tab row.

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.

func LoadTask

func LoadTask(ctx context.Context, workDir, taskID string) (*Task, error)

LoadTask runs `td show --json` in workDir.

type TaskMsg

type TaskMsg struct {
	WorkspaceID string
	TaskID      string
	Task        *Task
	Err         error
}

TaskMsg is a completed `td show --json` for one worktree.

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.

func (*TaskView) Scroll

func (t *TaskView) Scroll(delta, height int)

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

func (v *View) ApplyLoadedSnapshot(snapshot *Snapshot, workdir, workspaceID string) tea.Cmd

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) FileCount

func (v *View) FileCount() int

FileCount is the number of working-tree files in the current scope.

func (*View) LoadSelectedCommit

func (v *View) LoadSelectedCommit(workdir, workspaceID string) tea.Cmd

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

func (v *View) ScrollContent(delta int)

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

func (v *View) TotalItems() int

TotalItems is files + commits, the navigable left-pane length.

type ViewMode

type ViewMode int

ViewMode is how a per-file diff is drawn.

const (
	ViewUnified ViewMode = iota
	ViewSideBySide
	ViewFullFile
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL