framework

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package framework provides the core wizard orchestration system.

A wizard is a multi-step interactive flow that guides users through complex operations. It manages step navigation, skip conditions, callbacks, and summary display.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BorderStyle

func BorderStyle() lipgloss.Style

BorderStyle wraps the entire wizard (left border only)

func ErrorStyle added in v0.14.0

func ErrorStyle() lipgloss.Style

ErrorStyle for validation error messages

func FilterLabelStyle

func FilterLabelStyle() lipgloss.Style

FilterLabelStyle for the "Filter:" label

func FilterRunes

func FilterRunes(runes []rune, filter RuneFilter) string

FilterRunes returns characters from a rune slice that pass the filter. If filter is nil, defaults to RuneFilterNone (all printable).

func FilterStyle

func FilterStyle() lipgloss.Style

FilterStyle for the filter text being typed

func HelpStyle

func HelpStyle() lipgloss.Style

HelpStyle for help text at the bottom

func InfoStyle

func InfoStyle() lipgloss.Style

InfoStyle for informational text (e.g., "Selected: repo1, repo2")

func MatchHighlightStyle

func MatchHighlightStyle() lipgloss.Style

MatchHighlightStyle for highlighting fuzzy matched characters

func OptionDescriptionStyle

func OptionDescriptionStyle() lipgloss.Style

OptionDescriptionStyle for two-row option descriptions

func OptionDisabledStyle

func OptionDisabledStyle() lipgloss.Style

OptionDisabledStyle for disabled/greyed options

func OptionNormalStyle

func OptionNormalStyle() lipgloss.Style

OptionNormalStyle for regular options

func OptionSelectedStyle

func OptionSelectedStyle() lipgloss.Style

OptionSelectedStyle for the cursor-highlighted option

func RuneFilterNoSpaces

func RuneFilterNoSpaces(r rune) bool

RuneFilterNoSpaces allows printable characters except spaces. Use for branch names, identifiers, etc.

func RuneFilterNone

func RuneFilterNone(r rune) bool

RuneFilterNone allows all printable characters.

func StepActiveStyle

func StepActiveStyle() lipgloss.Style

StepActiveStyle for the current step tab

func StepArrowStyle

func StepArrowStyle() lipgloss.Style

StepArrowStyle for arrows between steps

func StepCheckStyle

func StepCheckStyle() lipgloss.Style

StepCheckStyle for the checkmark on completed steps

func StepCompletedStyle

func StepCompletedStyle() lipgloss.Style

StepCompletedStyle for completed step tabs

func StepInactiveStyle

func StepInactiveStyle() lipgloss.Style

StepInactiveStyle for unvisited step tabs

func SummaryLabelStyle

func SummaryLabelStyle() lipgloss.Style

SummaryLabelStyle for summary field labels

func SummaryValueStyle

func SummaryValueStyle() lipgloss.Style

SummaryValueStyle for summary field values

func TitleStyle

func TitleStyle() lipgloss.Style

TitleStyle for the wizard title

Types

type Option

type Option struct {
	Label       string // Display text
	Value       any    // Actual value
	Description string // Optional description (for disabled reason)
	Disabled    bool   // Whether option is disabled/unselectable
}

Option represents a selectable item in list-based steps.

type RuneFilter

type RuneFilter func(r rune) bool

RuneFilter determines which runes are allowed in input.

type Step

type Step interface {
	// ID returns a unique identifier for this step.
	ID() string

	// Title returns the display title for the step tab.
	Title() string

	// Init returns an initial command when entering this step.
	Init() tea.Cmd

	// Update handles key events and returns the updated step,
	// a command to run, and a result indicating navigation.
	Update(msg tea.KeyPressMsg) (Step, tea.Cmd, StepResult)

	// View renders the step content.
	View() string

	// Help returns the help text for this step.
	Help() string

	// Value returns the step's current value for summary display.
	Value() StepValue

	// IsComplete returns true if the step has a valid selection.
	IsComplete() bool

	// Reset clears the step's selection/input.
	Reset()

	// HasClearableInput returns true if the step has input that can be cleared.
	// Used to determine ESC behavior: clear input first, then cancel.
	HasClearableInput() bool

	// ClearInput clears any user input (filter, text field, etc).
	// Returns a command to run (e.g., textinput.Blink for cursor).
	ClearInput() tea.Cmd
}

Step is the interface for wizard steps.

type StepResult

type StepResult int

StepResult indicates what action to take after a step update.

const (
	// StepContinue means stay on the current step.
	StepContinue StepResult = iota
	// StepAdvance means move to the next step.
	StepAdvance
	// StepBack means move to the previous step.
	StepBack
	// StepSubmitIfReady means advance to the next step; if this was the last step, the wizard finishes.
	StepSubmitIfReady
)

type StepValue

type StepValue struct {
	Key   string // Field name (e.g., "Branch")
	Label string // Display value (e.g., "feature-branch")
	Raw   any    // Actual value (can be string, bool, []string, etc.)
}

StepValue holds the result of a completed step.

type Wizard

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

Wizard orchestrates a multi-step interactive flow.

func NewWizard

func NewWizard(title string) *Wizard

NewWizard creates a new wizard with the given title.

func (*Wizard) AddStep

func (w *Wizard) AddStep(step Step) *Wizard

AddStep adds a step to the wizard.

func (*Wizard) AllStepsComplete

func (w *Wizard) AllStepsComplete() bool

AllStepsComplete returns true if all steps have values.

func (*Wizard) CurrentStepID

func (w *Wizard) CurrentStepID() string

CurrentStepID returns the current step's ID, or "summary" if on summary.

func (*Wizard) GetBool

func (w *Wizard) GetBool(id string) bool

GetBool returns a step's value as a bool.

func (*Wizard) GetStep

func (w *Wizard) GetStep(id string) Step

GetStep returns a step by ID.

func (*Wizard) GetString

func (w *Wizard) GetString(id string) string

GetString returns a step's value as a string.

func (*Wizard) GetStrings

func (w *Wizard) GetStrings(id string) []string

GetStrings returns a step's value as a string slice.

func (*Wizard) GetValue

func (w *Wizard) GetValue(id string) StepValue

GetValue returns a step's value by ID.

func (*Wizard) Init

func (w *Wizard) Init() tea.Cmd

func (*Wizard) IsCancelled

func (w *Wizard) IsCancelled() bool

IsCancelled returns true if the wizard was cancelled.

func (*Wizard) OnComplete

func (w *Wizard) OnComplete(stepID string, callback func(*Wizard)) *Wizard

OnComplete sets a callback to run when a step completes.

func (*Wizard) Run

func (w *Wizard) Run() (*Wizard, error)

Run executes the wizard and returns when complete or cancelled. The TUI renders to stderr so stdout remains available for piping (e.g., cd $(wt cd -i) works correctly).

func (*Wizard) SetCurrentStep

func (w *Wizard) SetCurrentStep(id string)

SetCurrentStep sets the current step by ID.

func (*Wizard) SkipWhen

func (w *Wizard) SkipWhen(stepID string, condition func(*Wizard) bool) *Wizard

SkipWhen sets a condition for skipping a step.

func (*Wizard) StepCount

func (w *Wizard) StepCount() int

StepCount returns the number of steps (excluding summary).

func (*Wizard) Update

func (w *Wizard) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Wizard) View

func (w *Wizard) View() tea.View

func (*Wizard) WithInfoLine

func (w *Wizard) WithInfoLine(fn func(*Wizard) string) *Wizard

WithInfoLine sets a dynamic info line function.

func (*Wizard) WithSkipSummary

func (w *Wizard) WithSkipSummary(skip bool) *Wizard

WithSkipSummary sets whether to skip the summary step and finish after the last step. Useful for single-step wizards where a confirmation summary is unnecessary.

func (*Wizard) WithSummary

func (w *Wizard) WithSummary(title string) *Wizard

WithSummary sets the summary step title.

Jump to

Keyboard shortcuts

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