Documentation
¶
Overview ¶
Package tree provides a renderer for branch tree visualizations.
Index ¶
- Constants
- type BranchAnnotation
- type CachedBranchRender
- type CachedTreeData
- type Data
- type MergedParentDisplay
- type MockTreeData
- func (m *MockTreeData) Children(branchName string) []string
- func (m *MockTreeData) CurrentBranch() string
- func (m *MockTreeData) IsFixed(branchName string) bool
- func (m *MockTreeData) IsTrunk(branchName string) bool
- func (m *MockTreeData) Parent(branchName string) string
- func (m *MockTreeData) Trunk() string
- type Model
- type RenderMode
- type RenderOptions
- type RenderedBranch
- type StackTree
- func (t *StackTree) Children(branchName string) []string
- func (t *StackTree) CurrentBranch() string
- func (t *StackTree) IsFixed(branchName string) bool
- func (t *StackTree) IsTrunk(branchName string) bool
- func (t *StackTree) Parent(branchName string) string
- func (t *StackTree) ToRenderer() *StackTreeRenderer
- func (t *StackTree) ToRendererWithFixed(isBranchFixed func(string) bool) *StackTreeRenderer
- func (t *StackTree) Trunk() string
- type StackTreeRenderer
- func (r *StackTreeRenderer) FormatAnnotationColored(annotation BranchAnnotation) string
- func (r *StackTreeRenderer) RenderBranchList(branches []string) []string
- func (r *StackTreeRenderer) RenderStack(branchName string, opts RenderOptions) []string
- func (r *StackTreeRenderer) RenderStackCached(branchName string, opts RenderOptions) *CachedTreeData
- func (r *StackTreeRenderer) RenderStackDetailed(branchName string, opts RenderOptions) []RenderedBranch
- func (r *StackTreeRenderer) SetAnnotation(branchName string, annotation BranchAnnotation)
- func (r *StackTreeRenderer) SetAnnotations(annotations map[string]BranchAnnotation)
Constants ¶
const ( // CurrentBranchSymbol is the symbol used for the current branch in tree views CurrentBranchSymbol = "◉" // BranchSymbol is the symbol used for regular branches in tree views BranchSymbol = "◯" // PRStateMerged indicates the PR has been merged PRStateMerged = "MERGED" // PRStateClosed indicates the PR has been closed PRStateClosed = "CLOSED" // CheckStatusNone indicates no CI status CheckStatusNone = "NONE" // CheckStatusPassing indicates CI is passing CheckStatusPassing = "PASSING" // CheckStatusFailing indicates CI is failing CheckStatusFailing = "FAILING" // CheckStatusPending indicates CI is pending CheckStatusPending = "PENDING" // RestackSuggestedLabel marks branches where restacking may reduce review churn. RestackSuggestedLabel = "(restack suggested)" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BranchAnnotation ¶
type BranchAnnotation struct {
PRNumber *int
PRAction string // "create", "update", "skip", ""
CheckStatus string // PASSING, FAILING, PENDING, NONE, ""
ReviewStatus string // "Approved", "In Review", "Changes Requested", "Commented", ""
IsDraft bool
IsLocked bool
IsFrozen bool
NeedsRestack bool
CustomLabel string // Additional text to display after branch name
Scope string
ExplicitScope string
CommitCount int
LinesAdded int
LinesDeleted int
PRState string // "OPEN", "MERGED", "CLOSED"
// WorktreePath is set if this branch is the stack root of a managed worktree
WorktreePath string
// IsEmptyWorktree indicates this is a worktree anchor with no child branches
IsEmptyWorktree bool
// LocalSHA is the short commit SHA of the branch head (for debugging/diagnostics)
LocalSHA string
// MergedDownstack holds historical merged parents for display
MergedDownstack []MergedParentDisplay
// CommitMessages holds formatted commit messages (e.g., "abc123 Commit message")
// Used when ShowCommitMessages is enabled in RenderOptions
CommitMessages []string
// PRURL is the GitHub PR URL for this branch
PRURL string
}
BranchAnnotation holds per-branch display metadata
type CachedBranchRender ¶
type CachedBranchRender struct {
Name string // Branch name
LinesUnselected []string // Lines without selection (padding prefix, no highlight)
CursorLineSelected string // The cursor line with selection styling (cursor prefix + highlighted name)
CursorLineIndex int // Which line gets the cursor
IsNonSelectable bool // If true, never show as selected
}
CachedBranchRender holds pre-rendered branch content with both selected and unselected versions. This allows fast updates when only the selection changes.
type CachedTreeData ¶
type CachedTreeData struct {
Branches []CachedBranchRender
}
CachedTreeData holds the entire cached tree structure for fast selection updates.
func (*CachedTreeData) ApplySelection ¶
func (c *CachedTreeData) ApplySelection(selectedBranch string) []RenderedBranch
ApplySelection applies selection styling to cached branch data. This is fast because it only swaps the cursor line between selected/unselected versions.
type Data ¶
type Data interface {
// CurrentBranch returns the name of the currently checked out branch
CurrentBranch() string
// Trunk returns the name of the trunk/main branch
Trunk() string
// Children returns the child branches of the given branch
Children(branchName string) []string
// Parent returns the parent branch of the given branch
Parent(branchName string) string
// IsTrunk returns whether the given branch is a trunk branch
IsTrunk(branchName string) bool
// IsFixed returns whether the branch is up-to-date with its parent
IsFixed(branchName string) bool
}
Data provides the tree structure data for rendering. This interface abstracts the source of tree data, making the renderer more testable and decoupled from specific implementations.
type MergedParentDisplay ¶
type MergedParentDisplay struct {
BranchName string
PRNumber *int
PRState string // "MERGED", "CLOSED"
}
MergedParentDisplay represents a historical merged parent for display purposes
type MockTreeData ¶
type MockTreeData struct {
// CurrentVal is the current branch name
CurrentVal string
// TrunkVal is the trunk branch name
TrunkVal string
// ChildrenMap maps branch name to child branch names
ChildrenMap map[string][]string
// ParentsMap maps branch name to parent branch name
ParentsMap map[string]string
// FixedMap maps branch name to whether it's fixed (up-to-date)
FixedMap map[string]bool
}
MockTreeData provides test data for tree rendering. It implements the TreeData interface and is exported to be used in both tests and the TUI storyboard.
func NewMockTreeData ¶
func NewMockTreeData() *MockTreeData
NewMockTreeData creates a new MockTreeData with sample data.
func (*MockTreeData) Children ¶
func (m *MockTreeData) Children(branchName string) []string
Children implements TreeData.Children
func (*MockTreeData) CurrentBranch ¶
func (m *MockTreeData) CurrentBranch() string
CurrentBranch implements TreeData.CurrentBranch
func (*MockTreeData) IsFixed ¶
func (m *MockTreeData) IsFixed(branchName string) bool
IsFixed implements TreeData.IsFixed
func (*MockTreeData) IsTrunk ¶
func (m *MockTreeData) IsTrunk(branchName string) bool
IsTrunk implements TreeData.IsTrunk
func (*MockTreeData) Parent ¶
func (m *MockTreeData) Parent(branchName string) string
Parent implements TreeData.Parent
type Model ¶
type Model struct {
Renderer *StackTreeRenderer
Options RenderOptions
Width int
Height int
}
Model wraps StackTreeRenderer to make it a tea.Model for the storyboard
func NewModel ¶
func NewModel(renderer *StackTreeRenderer) *Model
NewModel creates a new Model with the given renderer.
type RenderMode ¶
type RenderMode int
RenderMode specifies the rendering style for the tree.
const ( // RenderModeFull shows multi-line branches with stats and summary. // Each branch takes multiple lines: branch info line, summary line, spacer. RenderModeFull RenderMode = iota // RenderModeCompact shows single-line branches with minimal info. // Good for quick overviews and narrower terminal widths. RenderModeCompact // RenderModeSelect shows single-line branches optimized for selection UI. // Similar to Compact but includes selection-related features. RenderModeSelect )
type RenderOptions ¶
type RenderOptions struct {
// Mode specifies the rendering style. Defaults to RenderModeFull.
Mode RenderMode
// Steps limits traversal depth in each direction.
Steps *int
// OmitCurrentBranch hides the current branch from the tree.
OmitCurrentBranch bool
// NoStyleBranchName disables styling on branch names.
NoStyleBranchName bool
// HideStats hides commit count and line change stats.
HideStats bool
// HideSummary hides the entire summary line (stats, PR info, CI status).
HideSummary bool
// ShowSHAs shows commit SHAs next to branch names (for debugging).
ShowSHAs bool
// ShowCommitMessages shows commit messages below each branch.
// Uses CommitMessages from BranchAnnotation.
ShowCommitMessages bool
// SelectedBranch is the name of the currently selected branch (for cursor).
SelectedBranch string
// Collapsed maps branch names to whether they are collapsed.
Collapsed map[string]bool
// SearchQuery is the current search filter text.
SearchQuery string
// SearchMatches maps branch names to whether they match the search.
SearchMatches map[string]bool
// NonSelectable marks branches that are visible but not selectable.
NonSelectable map[string]bool
// SkipSelectionPrefix omits the selection cursor/padding prefix.
SkipSelectionPrefix bool
}
RenderOptions configures rendering behavior
type RenderedBranch ¶
type RenderedBranch struct {
Name string
Lines []string
// CursorLineIndex is the index within Lines where the selection cursor should appear (typically 0)
CursorLineIndex int
// CursorLineSelected is the pre-computed cursor line with selection styling.
// This is populated during render to enable fast selection updates without re-rendering.
CursorLineSelected string
}
RenderedBranch represents a branch and its rendered lines
type StackTree ¶
type StackTree struct {
Branches []string // branches in the stack, in order
CurrentBranchV string // the currently checked out branch
TrunkBranch string // the trunk/main branch name
ParentMap map[string]string // branch -> parent mapping
ChildrenMap map[string][]string // branch -> children mapping
FixedMap map[string]bool // branch -> whether it's fixed (optional)
}
StackTree represents the structure of a branch stack for rendering. It encapsulates parent/child relationships and metadata needed to visualize stacks. This type is designed to be embedded in events and other contexts where stack visualization is needed.
StackTree implements the Data interface, allowing it to be used directly with NewRenderer for tree visualization.
func NewStackTree ¶
NewStackTree creates a StackTree from a list of branches. It builds the parent/child relationship maps from the branch metadata.
func (*StackTree) CurrentBranch ¶
CurrentBranch returns the currently checked out branch.
func (*StackTree) IsFixed ¶
IsFixed returns whether the branch is up-to-date with its parent. If FixedMap is nil, all branches are considered fixed.
func (*StackTree) ToRenderer ¶
func (t *StackTree) ToRenderer() *StackTreeRenderer
ToRenderer converts the tree data into a StackTreeRenderer with default settings. All branches are considered "fixed" (no restack indicators).
func (*StackTree) ToRendererWithFixed ¶
func (t *StackTree) ToRendererWithFixed(isBranchFixed func(string) bool) *StackTreeRenderer
ToRendererWithFixed converts the tree data into a StackTreeRenderer with custom fixed branch logic. The isBranchFixed function determines which branches should be marked as not needing restack.
type StackTreeRenderer ¶
type StackTreeRenderer struct {
Annotations map[string]BranchAnnotation
// contains filtered or unexported fields
}
StackTreeRenderer renders branch trees with annotations
func NewRenderer ¶
func NewRenderer(data Data) *StackTreeRenderer
NewRenderer creates a new tree renderer from a Data source. This is the preferred constructor as it uses a clean interface.
func (*StackTreeRenderer) FormatAnnotationColored ¶
func (r *StackTreeRenderer) FormatAnnotationColored(annotation BranchAnnotation) string
FormatAnnotationColored returns a colored string representation of a branch annotation
func (*StackTreeRenderer) RenderBranchList ¶
func (r *StackTreeRenderer) RenderBranchList(branches []string) []string
RenderBranchList renders a simple list of branches with annotations (no tree structure)
func (*StackTreeRenderer) RenderStack ¶
func (r *StackTreeRenderer) RenderStack(branchName string, opts RenderOptions) []string
RenderStack renders the full stack tree starting from a branch
func (*StackTreeRenderer) RenderStackCached ¶
func (r *StackTreeRenderer) RenderStackCached(branchName string, opts RenderOptions) *CachedTreeData
RenderStackCached renders the tree and returns cached data for fast selection updates. It renders once, generating both selected and unselected cursor lines in a single pass.
func (*StackTreeRenderer) RenderStackDetailed ¶
func (r *StackTreeRenderer) RenderStackDetailed(branchName string, opts RenderOptions) []RenderedBranch
RenderStackDetailed renders the full stack tree and returns detailed branch info
func (*StackTreeRenderer) SetAnnotation ¶
func (r *StackTreeRenderer) SetAnnotation(branchName string, annotation BranchAnnotation)
SetAnnotation sets the annotation for a branch
func (*StackTreeRenderer) SetAnnotations ¶
func (r *StackTreeRenderer) SetAnnotations(annotations map[string]BranchAnnotation)
SetAnnotations sets annotations for multiple branches