Documentation
¶
Overview ¶
Package worktreedelete owns the "Delete Worktree?" confirmation shared by every surface that can delete a worktree.
The project workspace (internal/plugins/workspace) and the global Workspaces browser (internal/overview) are two projections of one model, so the confirmation they raise must be one construction, not two that resemble each other. This package holds the whole of it: the modal's sections, the branch cleanup options, and the key/mouse routing that turns a press into a decision. Hosts own only what is genuinely theirs — how the target is selected, and how the deletion is executed afterwards.
Index ¶
- Constants
- func ClampWidth(avail int) int
- type Dirtiness
- type Outcome
- type State
- func (s *State) Active() bool
- func (s *State) Clear()
- func (s *State) DeleteRemoteBranch() bool
- func (s *State) HandleKey(avail int, msg tea.KeyPressMsg) (Outcome, tea.Cmd)
- func (s *State) HandleMouse(avail int, msg tea.MouseMsg, handler *mouse.Handler) Outcome
- func (s *State) Invalidate()
- func (s *State) Modal(avail int) *modal.Modal
- func (s *State) Open(target Target, isMainBranch bool)
- func (s *State) Target() Target
- func (s *State) WheelAtBoundary(avail int, msg tea.MouseWheelMsg, handler *mouse.Handler) bool
- type Target
Constants ¶
const ( LocalBranchID = "delete-confirm-local-branch" RemoteBranchID = "delete-confirm-remote-branch" DeleteID = "delete-confirm-delete" CancelID = "delete-confirm-cancel" )
Action IDs. They are exported because hosts route mouse and keyboard actions through the same identifiers.
const ( // DirtyLine is shown only when git reported work that removal would destroy. DirtyLine = "Uncommitted changes will be lost" // CleanLine is shown when git reported a clean worktree. CleanLine = "No uncommitted changes to lose" // UnknownDirtinessLine is shown until git answers, and if it cannot. UnknownDirtinessLine = "Checking for uncommitted changes…" )
The three things the confirmation can say about uncommitted work. They are exported so each host's tests assert against the shared wording rather than its own copy of it.
const Title = "Delete Worktree?"
Title is the confirmation's heading. Exported so a host's tests can assert the shared modal is the one on screen.
const Width = 58
Width is the confirmation's preferred width before clamping.
Variables ¶
This section is empty.
Functions ¶
func ClampWidth ¶
ClampWidth is the confirmation's width on a surface `avail` cells wide.
Types ¶
type Dirtiness ¶
type Dirtiness int
Dirtiness is what the host knows about uncommitted work in the target.
It is three values rather than a bool because a confirmation opens before git can answer: "we have not asked yet" and "we asked and it is clean" are different sentences, and rendering the second while the first is true would be the same lie as the old unconditional warning, only pointed the other way.
func ProbeDirtiness ¶
ProbeDirtiness asks git whether a worktree holds work a removal would destroy, in the form the confirmation renders.
Both hosts call this, off the keypress path, when the confirmation opens — one `git status` for the one worktree the user named, rather than a status per worktree per inventory refresh. An unreadable worktree stays Unknown: telling a user their worktree is clean because git failed is exactly the reassurance this ticket exists to remove. A missing directory is Unknown too; the confirmation already says the directory is gone.
type State ¶
type State struct {
// IsMainBranch protects the repository's primary branch: while true the
// branch cleanup options are not offered at all.
IsMainBranch bool
// HasRemote reports that the branch exists on origin. Hosts may resolve it
// asynchronously; the modal reads it at render time.
HasRemote bool
// DeleteLocal and DeleteRemote are the optional branch cleanup choices.
DeleteLocal bool
DeleteRemote bool
// Dirty is what git says about uncommitted work in the target. Hosts
// resolve it asynchronously, as they do HasRemote, and call Invalidate.
Dirty Dirtiness
// contains filtered or unexported fields
}
State is one open confirmation. The zero value is closed.
func (*State) DeleteRemoteBranch ¶
DeleteRemoteBranch reports whether the remote branch should be deleted: the box is only meaningful when a remote branch was actually found.
func (*State) HandleKey ¶
HandleKey routes a key press to the open confirmation. Hosts act on the returned outcome; the tea.Cmd belongs to the modal's own widgets.
func (*State) HandleMouse ¶
HandleMouse routes a mouse event to the open confirmation.
func (*State) Invalidate ¶
func (s *State) Invalidate()
Invalidate discards the cached modal so the next render rebuilds it. Hosts call it after an asynchronous answer (remote branch existence) lands.
func (*State) Modal ¶
Modal builds (and caches) the confirmation for a surface `avail` cells wide. It returns nil while no confirmation is open.
func (*State) Open ¶
Open arms the confirmation for a target. isMainBranch is the host's answer about the repository's primary branch; HasRemote may be filled in later.
func (*State) WheelAtBoundary ¶
WheelAtBoundary reports that the confirmation cannot scroll further, so the host may pass the wheel on.