checkoutview

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package checkoutview renders the interactive stack picker shown by `gh stack checkout` when no target is given. It reconciles the locally tracked stacks with the stacks returned by the Stacks REST API into a single table, labels each as Local or Remote, and lets the user filter, search, and select one to check out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is the Bubble Tea model for the interactive checkout stack picker.

func New

func New(rows []StackRow) Model

New creates a picker model over the given reconciled rows.

func (Model) Cancelled

func (m Model) Cancelled() bool

Cancelled reports whether the user dismissed the picker without selecting.

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Result

func (m Model) Result() (StackRow, bool)

Result returns the selected row and whether one was chosen (Enter). It is false when the user cancelled or nothing was selectable.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model) View

func (m Model) View() string

type StackRow

type StackRow struct {
	Number       int // stack number; 0 when unknown (local-only, not pushed)
	Type         StackType
	BottomBranch string
	TopBranch    string
	Base         string
	Status       StatusCounts
	Created      time.Time
	HasCreated   bool

	// Branches is the full ordered list of branch names in the stack. Only
	// BottomBranch and TopBranch are displayed; the complete list exists so
	// search can match any branch, including mid-stack ones.
	Branches []string

	// LocalStack points at the local stack when Type == TypeLocal, so the caller
	// can check out its branches directly without cloning. It is nil for
	// remote-only rows, which are cloned by stack number instead.
	LocalStack *stack.Stack
}

StackRow is a single reconciled entry shown in the checkout picker.

func BuildRows

func BuildRows(local []stack.Stack, remote []github.RemoteStack) []StackRow

BuildRows reconciles the local stacks with the remote stacks into the ordered list shown in the picker. Local stacks own the "Local" type even when they are tracked on the remote; remote stacks with no local match are "Remote". Fully-merged stacks (every PR merged) are omitted. The local slice must be the caller's live stack slice, since rows retain pointers into it.

func (StackRow) CreatedDisplay

func (r StackRow) CreatedDisplay() string

CreatedDisplay renders the creation time as a compact age, or "—" when unknown.

func (StackRow) NumberDisplay

func (r StackRow) NumberDisplay() string

NumberDisplay renders the stack number, or "—" when it is unknown.

func (StackRow) Summary

func (r StackRow) Summary() string

Summary returns "bottom...top" (or a single branch when the stack has one branch, or the ends coincide).

type StackType

type StackType int

StackType classifies where a stack lives.

const (
	// TypeLocal means the stack is present in the local stack file. It may also
	// be tracked on the remote; per the picker's simplification, anything
	// available locally is "Local".
	TypeLocal StackType = iota
	// TypeRemote means the stack exists only on the remote.
	TypeRemote
)

func (StackType) String

func (t StackType) String() string

String returns the human-readable label for the type column.

type StatusCounts

type StatusCounts struct {
	Merged   int // merged PRs (purple)
	Open     int // open, non-merged PRs (green)
	Closed   int // closed, non-merged PRs (red)
	Unpushed int // branches with no PR yet (gray)
}

StatusCounts summarizes a stack's composition for the status bar. Each field is a count of branches/PRs in that state.

func (StatusCounts) Total

func (c StatusCounts) Total() int

Total returns the number of branches/PRs represented.

Jump to

Keyboard shortcuts

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