ui

package
v4.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset         = "\033[0m"
	Bold          = "\033[1m"
	Strikethrough = "\033[9m"
	Red           = "\033[31m"
	Green         = "\033[32m"
	Yellow        = "\033[33m"
	Blue          = "\033[34m"
	Magenta       = "\033[35m"
	Cyan          = "\033[36m"
	Gray          = "\033[90m"
)

Colors for terminal output

View Source
const (
	ExitSuccess        = 0  // Success
	ExitGeneral        = 1  // General error
	ExitUsage          = 2  // Usage/argument error
	ExitConflict       = 3  // Rebase conflict
	ExitNotInRepo      = 4  // Not in a git repository
	ExitNotInStack     = 5  // Current branch is not in a stack
	ExitAuthRequired   = 6  // GitHub authentication required
	ExitBranchNotFound = 7  // Branch not found
	ExitNetworkError   = 8  // Network/remote error
	ExitUserCancelled  = 10 // User cancelled operation
)

Exit codes for structured error reporting

View Source
const MaxBranchNameWidth = 50

MaxBranchNameWidth is the maximum width for branch names before truncation

View Source
const SpinnerDelay = 1500 * time.Millisecond

SpinnerDelay is the delay before showing a spinner (only show for slow operations)

Variables

View Source
var (
	IconSuccess  = "\uf00c"
	IconError    = "\uf00d"
	IconWarning  = "\uf071"
	IconInfo     = "\uf05a"
	IconPending  = "\uf192"
	IconArrow    = "\uf061"
	IconPointer  = "\uf0a4"
	IconBranch   = "\ue725"
	IconUp       = "\uf062"
	IconDown     = "\uf063"
	IconSync     = "\uf021"
	IconCancel   = "\uf05e"
	IconBullet   = "\uf111"
	IconApproved = "\uf058"
	IconChanges  = "\uf06a"
	IconConflict = "\uf071"
	IconNew      = "\uf067"
	IconPush     = "\uf093"
	IconStack    = "\uf24d"
	IconRocket   = "\uf135"
	IconBack     = "\uf060"
)

Icons for terminal rendering. Defaults to Nerd Font glyphs; set EZS_ASCII=1 to use plain ASCII fallbacks.

View Source
var ErrBack = fmt.Errorf("back")

ErrBack is returned when the user selects the back option

View Source
var YesMode bool

YesMode, when true, makes all ConfirmTUI / Confirm calls auto-return true without showing any interactive dialog.

Functions

func Confirm

func Confirm(prompt string) bool

Confirm asks the user for confirmation (simple text-based)

func ConfirmTUI

func ConfirmTUI(prompt string) bool

ConfirmTUI shows a TUI yes/no dialog with Yes highlighted by default. ESC cancels (returns false).

func ConfirmTUIWithDefault

func ConfirmTUIWithDefault(prompt string, defaultYes bool) bool

ConfirmTUIWithDefault shows a TUI yes/no dialog. defaultYes controls which option is highlighted; ESC returns the default.

func EditWithEditor

func EditWithEditor(initialContent, fileExtension string) (string, error)

EditWithEditor opens the user's preferred editor with the initial content and returns the edited content. If the user saves and exits, the content is returned. If the user aborts (empty file or error), an error is returned. The editor is determined by $EDITOR, $VISUAL, or falls back to "vim".

func Error

func Error(msg string)

Error prints an error message to stderr

func GetExitCode

func GetExitCode(err error) int

GetExitCode returns the exit code for an error, defaulting to ExitGeneral

func Hyperlink(url, text string) string

Hyperlink wraps text in OSC 8 escape sequence for clickable terminal links

func Info

func Info(msg string)

Info prints an info message to stderr

func PrintStack

func PrintStack(stack *config.Stack, currentBranch string, showStatus bool, statusMap map[string]*BranchStatus)

PrintStack prints a visual representation of a stack using tree-style indentation. If showStatus is true, includes CI/PR status after the PR column.

func Prompt

func Prompt(prompt, defaultVal string) string

Prompt asks for text input with a prompt and optional default value Returns the user input or the default if empty input is given

func PromptPath

func PromptPath(promptText, defaultVal string) string

PromptPath asks for a file path with tab completion support Returns the user input or the default if empty input is given

func PromptRequired

func PromptRequired(prompt string) string

PromptRequired asks for text input and keeps asking until a non-empty value is provided

func SelectBranch

func SelectBranch(branches []*config.Branch, prompt string) (*config.Branch, error)

SelectBranch uses fzf to select a branch from a list

func SelectBranchWithStacks

func SelectBranchWithStacks(branches []*config.Branch, stacks []*config.Stack, prompt string) (*config.Branch, error)

SelectBranchWithStacks uses fzf to select a branch with optional stack preview

func SelectOption

func SelectOption(options []string, prompt string) (int, error)

SelectOption uses fzf to select from a list of options Returns the 0-based index of the selected option

func SelectOptionWithBack

func SelectOptionWithBack(options []string, prompt string) (int, error)

SelectOptionWithBack uses fzf to select from a list of options with a back option. Returns the 0-based index of the selected option, or ErrBack if back was selected. The back option is displayed as an unnumbered "← back" at the end of the list.

func SelectOptionWithSuggested

func SelectOptionWithSuggested(options []string, prompt string, suggestedIdx int) (int, error)

SelectOptionWithSuggested uses fzf to select from a list of options suggestedIdx is the 0-based index of the suggested option (-1 for none) The suggested option will be marked with "(suggested)" and appear first Returns the 0-based index of the selected option

func SelectStack

func SelectStack(stacks []*config.Stack, prompt string) (*config.Stack, error)

SelectStack uses fzf to select a stack

func SelectTUI

func SelectTUI(options []string, prompt string, defaultIdx int) int

SelectTUI shows a TUI selection menu with arrow key navigation options is the list of options to display prompt is the question to ask defaultIdx is the 0-based index of the default selected option Returns the 0-based index of the selected option, or -1 if cancelled

func SetBackend added in v4.4.0

func SetBackend(b Backend)

SetBackend replaces the active UI backend (e.g. to MCPBackend for MCP mode).

func Success

func Success(msg string)

Success prints a success message to stderr

func Warn

func Warn(msg string)

Warn prints a warning message to stderr

func WithSpinner

func WithSpinner(message string, fn func() error) error

WithSpinner runs a function with a delayed spinner The spinner only shows if the function takes longer than SpinnerDelay

Types

type Backend added in v4.4.0

type Backend interface {
	// Confirm asks a yes/no question, defaulting to yes.
	Confirm(prompt string) bool

	// ConfirmWithDefault asks a yes/no question with a configurable default.
	ConfirmWithDefault(prompt string, defaultYes bool) bool

	// Select shows a selection menu and returns the 0-based index, or -1 if cancelled.
	Select(options []string, prompt string, defaultIdx int) int

	// SelectOption presents options via fzf-style selection and returns the 0-based index.
	SelectOption(options []string, prompt string) (int, error)

	// SelectOptionWithBack is like SelectOption but includes a "back" option.
	// Returns ErrBack if back was selected.
	SelectOptionWithBack(options []string, prompt string) (int, error)

	// SelectBranch selects a branch from a list.
	SelectBranch(branches []*config.Branch, prompt string) (*config.Branch, error)

	// SelectStack selects a stack from a list.
	SelectStack(stacks []*config.Stack, prompt string) (*config.Stack, error)

	// Prompt asks for text input with an optional default value.
	Prompt(prompt, defaultVal string) string

	// PromptRequired asks for text input, requiring a non-empty response.
	PromptRequired(prompt string) string
}

Backend defines the interface for interactive user prompts. Implementations include the terminal TUI (default) and MCP elicitation.

type BranchStatus

type BranchStatus struct {
	PRState     string // "OPEN", "MERGED", "CLOSED", "DRAFT", ""
	CIState     string // "success", "failure", "pending", "none", ""
	CISummary   string // e.g., "3/3 passed"
	Mergeable   string // "MERGEABLE", "CONFLICTING", "UNKNOWN"
	ReviewState string // "APPROVED", "CHANGES_REQUESTED", "REVIEW_REQUIRED", ""
	Additions   int    // Lines added relative to parent
	Deletions   int    // Lines removed relative to parent
}

BranchStatus contains status information for a branch

type DelayedSpinner

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

DelayedSpinner represents a spinner that only shows after a delay

func NewDelayedSpinner

func NewDelayedSpinner(message string) *DelayedSpinner

NewDelayedSpinner creates a spinner that only shows after the configured delay

func (*DelayedSpinner) Start

func (ds *DelayedSpinner) Start()

Start begins the delayed spinner (will only show if not stopped before delay)

func (*DelayedSpinner) Stop

func (ds *DelayedSpinner) Stop()

Stop stops the delayed spinner

type ElicitFunc added in v4.4.0

type ElicitFunc func(message string, schema map[string]interface{}) (*ElicitResult, error)

ElicitFunc sends an elicitation request to the MCP client. message is displayed to the user; schema is a JSON Schema for the form.

type ElicitResult added in v4.4.0

type ElicitResult struct {
	Action  string                 // "accept", "decline", or "cancel"
	Content map[string]interface{} // Form data; present only when Action is "accept"
}

ElicitResult holds the response from an MCP elicitation request.

type ExitError

type ExitError struct {
	Code    int
	Message string
}

ExitError wraps an error with a specific exit code

func NewExitError

func NewExitError(code int, format string, args ...interface{}) *ExitError

NewExitError creates an ExitError with the given code and message

func (*ExitError) Error

func (e *ExitError) Error() string

type MCPBackend added in v4.4.0

type MCPBackend struct {
	Elicit ElicitFunc
}

MCPBackend implements Backend using MCP elicitation.

func (*MCPBackend) Confirm added in v4.4.0

func (m *MCPBackend) Confirm(prompt string) bool

func (*MCPBackend) ConfirmWithDefault added in v4.4.0

func (m *MCPBackend) ConfirmWithDefault(prompt string, defaultYes bool) bool

func (*MCPBackend) Prompt added in v4.4.0

func (m *MCPBackend) Prompt(prompt, defaultVal string) string

func (*MCPBackend) PromptRequired added in v4.4.0

func (m *MCPBackend) PromptRequired(prompt string) string

func (*MCPBackend) Select added in v4.4.0

func (m *MCPBackend) Select(options []string, prompt string, defaultIdx int) int

func (*MCPBackend) SelectBranch added in v4.4.0

func (m *MCPBackend) SelectBranch(branches []*config.Branch, prompt string) (*config.Branch, error)

func (*MCPBackend) SelectOption added in v4.4.0

func (m *MCPBackend) SelectOption(options []string, prompt string) (int, error)

func (*MCPBackend) SelectOptionWithBack added in v4.4.0

func (m *MCPBackend) SelectOptionWithBack(options []string, prompt string) (int, error)

func (*MCPBackend) SelectStack added in v4.4.0

func (m *MCPBackend) SelectStack(stacks []*config.Stack, prompt string) (*config.Stack, error)

type Spinner

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

Spinner represents a simple loading spinner

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

type TerminalBackend added in v4.4.0

type TerminalBackend struct{}

TerminalBackend is the default Backend backed by the terminal TUI.

func (*TerminalBackend) Confirm added in v4.4.0

func (t *TerminalBackend) Confirm(prompt string) bool

func (*TerminalBackend) ConfirmWithDefault added in v4.4.0

func (t *TerminalBackend) ConfirmWithDefault(prompt string, defaultYes bool) bool

func (*TerminalBackend) Prompt added in v4.4.0

func (t *TerminalBackend) Prompt(prompt, defaultVal string) string

func (*TerminalBackend) PromptRequired added in v4.4.0

func (t *TerminalBackend) PromptRequired(prompt string) string

func (*TerminalBackend) Select added in v4.4.0

func (t *TerminalBackend) Select(options []string, prompt string, defaultIdx int) int

func (*TerminalBackend) SelectBranch added in v4.4.0

func (t *TerminalBackend) SelectBranch(branches []*config.Branch, prompt string) (*config.Branch, error)

func (*TerminalBackend) SelectOption added in v4.4.0

func (t *TerminalBackend) SelectOption(options []string, prompt string) (int, error)

func (*TerminalBackend) SelectOptionWithBack added in v4.4.0

func (t *TerminalBackend) SelectOptionWithBack(options []string, prompt string) (int, error)

func (*TerminalBackend) SelectStack added in v4.4.0

func (t *TerminalBackend) SelectStack(stacks []*config.Stack, prompt string) (*config.Stack, error)

type WorktreeInfo

type WorktreeInfo struct {
	Path   string
	Branch string
}

WorktreeInfo represents a worktree for UI selection

func SelectWorktree

func SelectWorktree(worktrees []WorktreeInfo, prompt string) (*WorktreeInfo, error)

SelectWorktree uses fzf to select a worktree from a list

func SelectWorktreeWithStackPreview

func SelectWorktreeWithStackPreview(worktrees []WorktreeInfo, stacks []*config.Stack, prompt string) (*WorktreeInfo, error)

SelectWorktreeWithStackPreview uses fzf to select a worktree with stack preview For worktrees not in any stack, the preview shows "Not part of a stack"

Jump to

Keyboard shortcuts

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