ui

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package ui provides terminal UI components for wt command output.

This package uses the Charm libraries (lipgloss, bubbles) for styled terminal output including tables and spinners.

Table Formatting

The primary components are table formatters for list and prune output:

  • FormatListTable: Renders worktree list with ID, repo, branch, status, last commit, notes, and PR info columns
  • FormatPruneTable: Simplified table for prune preview showing which worktrees will be removed and why

Tables use lipgloss styling with:

  • Normal borders in gray (color 240)
  • Bold headers
  • Cell padding for readability

PR Status Display

The list table shows PR status with visual indicators:

  • "-" : No upstream branch (can't have PR)
  • "?" : Not fetched yet
  • State + author + comments + reviews + URL for existing PRs
  • "✓" for approved, "◐" for pending reviews

Spinner (Experimental)

The Spinner type wraps Bubbletea for simple non-interactive progress indication. Currently unused but available for long-running operations.

Design Notes

Output is designed for terminal display with:

  • Monospace font assumptions
  • ANSI color support
  • Truncation for long values (e.g., notes limited to 30 chars)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatListTable added in v0.5.0

func FormatListTable(ctx context.Context, worktrees []git.Worktree, pathToID map[string]int, wtCache *cache.Cache) string

FormatListTable creates a formatted table for list command output

func FormatPruneTable added in v0.5.0

func FormatPruneTable(worktrees []git.Worktree, pathToID map[string]int, reasonMap map[string]string, pruneMap map[string]bool) string

FormatPruneTable creates a simplified table for prune output with reason column

func FormatSummary

func FormatSummary(removed, skipped int, dryRun bool) string

FormatSummary formats the summary line

Types

type BranchFetchResult added in v0.8.0

type BranchFetchResult struct {
	Branches []BranchInfo
}

BranchFetchResult contains branches with their worktree status.

type BranchFetcher added in v0.8.0

type BranchFetcher func(repoPath string) BranchFetchResult

BranchFetcher is a function that fetches branches for a repo path.

type BranchInfo added in v0.9.0

type BranchInfo struct {
	Name       string
	InWorktree bool
}

BranchInfo contains branch info including worktree status.

type CheckoutOptions added in v0.8.0

type CheckoutOptions struct {
	Branch        string
	NewBranch     bool
	IsWorktree    bool // True if selected branch already has a worktree (hooks only)
	Fetch         bool
	Cancelled     bool
	SelectedRepos []string // Selected repo paths (when outside a repo)
	SelectedHooks []string // Hook names to run (empty if NoHook is true)
	NoHook        bool     // True if no hooks selected
}

CheckoutOptions holds the options gathered from interactive mode.

func CheckoutInteractive added in v0.8.0

func CheckoutInteractive(params CheckoutWizardParams) (CheckoutOptions, error)

CheckoutInteractive runs the interactive checkout wizard.

type CheckoutWizardParams added in v0.8.0

type CheckoutWizardParams struct {
	Branches         []BranchInfo // Existing branches with worktree status
	AvailableRepos   []string     // All available repo paths
	RepoNames        []string     // Display names for repos
	PreSelectedRepos []int        // Indices of pre-selected repos (e.g., current repo when inside one)
	FetchBranches    BranchFetcher
	AvailableHooks   []HookInfo
	HooksFromCLI     bool // True if --hook or --no-hook was passed (skip hooks step)
}

CheckoutWizardParams contains parameters for the checkout wizard.

type ConfirmResult added in v0.8.0

type ConfirmResult struct {
	Confirmed bool
	Cancelled bool
}

Result types for interactive prompts

func Confirm added in v0.8.0

func Confirm(prompt string) (ConfirmResult, error)

Confirm shows a yes/no prompt and returns the user's choice.

type HookInfo added in v0.9.0

type HookInfo struct {
	Name        string
	Description string
	IsDefault   bool // Has on=["checkout"]
}

HookInfo contains hook display info for the wizard.

type PRFetcher added in v0.10.0

type PRFetcher func(repoPath string) ([]forge.OpenPR, error)

PRFetcher is a function that fetches open PRs for a repo path.

type PrCheckoutOptions added in v0.10.0

type PrCheckoutOptions struct {
	Cancelled     bool
	SelectedRepo  string   // Selected repo path (when outside a repo)
	SelectedPR    int      // Selected PR number
	SelectedHooks []string // Hook names to run (empty if NoHook is true)
	NoHook        bool     // True if no hooks selected
}

PrCheckoutOptions holds the options gathered from interactive mode.

func PrCheckoutInteractive added in v0.10.0

func PrCheckoutInteractive(params PrCheckoutWizardParams) (PrCheckoutOptions, error)

PrCheckoutInteractive runs the interactive PR checkout wizard.

type PrCheckoutWizardParams added in v0.10.0

type PrCheckoutWizardParams struct {
	AvailableRepos  []string   // All available repo paths
	RepoNames       []string   // Display names for repos
	PreSelectedRepo int        // Index of pre-selected repo (-1 if none)
	FetchPRs        PRFetcher  // Function to fetch PRs for a repo
	AvailableHooks  []HookInfo // Available hooks
	HooksFromCLI    bool       // True if --hook or --no-hook was passed (skip hooks step)
}

PrCheckoutWizardParams contains parameters for the PR checkout wizard.

type PruneOptions added in v0.9.0

type PruneOptions struct {
	SelectedIDs []int // Selected worktree IDs to prune
	Cancelled   bool
}

PruneOptions holds the options gathered from interactive mode.

func PruneInteractive added in v0.9.0

func PruneInteractive(params PruneWizardParams) (PruneOptions, error)

PruneInteractive runs the interactive prune wizard.

type PruneWizardParams added in v0.9.0

type PruneWizardParams struct {
	Worktrees    []PruneWorktreeInfo // All worktrees with their prune status
	IncludeClean bool                // Whether -c flag was set (affects which are pre-selected)
}

PruneWizardParams contains parameters for the prune wizard.

type PruneWorktreeInfo added in v0.9.0

type PruneWorktreeInfo struct {
	ID       int
	RepoName string
	Branch   string
	Reason   string // "Merged PR", "Merged branch", "Clean", "Dirty", "Not merged", "Has commits"
	IsDirty  bool   // Whether worktree has uncommitted changes
	Worktree git.Worktree
}

PruneWorktreeInfo contains worktree data for display in the wizard.

type SelectResult added in v0.8.0

type SelectResult struct {
	Value     string
	Index     int
	Cancelled bool
}

func Select added in v0.8.0

func Select(prompt string, options []string) (SelectResult, error)

Select shows a list selection prompt and returns the user's selection.

type Spinner

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

Spinner wraps a Bubbletea spinner for simple non-interactive use

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner with the given message

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner and clears the line

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

UpdateMessage changes the spinner message

type TextInputResult added in v0.8.0

type TextInputResult struct {
	Value     string
	Cancelled bool
}

func TextInput added in v0.8.0

func TextInput(prompt, placeholder string) (TextInputResult, error)

TextInput shows a text input prompt and returns the user's input.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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