Documentation
¶
Overview ¶
Package wizard provides a step-navigation state machine for multi-step flows: Next/Back advance or retreat the current step (clamped at the bounds), and View renders the step indicator via widgets.Stepper. It pairs naturally with widgets.Form/FormField for per-step validation errors, but owns no field state itself — the caller keeps that.
Example ¶
Next moves to the following step only when the step's validation passes.
package main
import (
"errors"
"fmt"
"github.com/ows4444/tui/wizard"
)
func main() {
m := wizard.New("account", "profile", "done")
err := m.Next(func() error { return errors.New("name is required") })
fmt.Println(m.Current(), err)
err = m.Next(func() error { return nil })
fmt.Println(m.Current(), err)
m.Back()
fmt.Println(m.Current())
}
Output: 0 name is required 1 <nil> 0
Index ¶
- type Model
- func (m *Model) Back()
- func (m Model) Current() int
- func (m Model) LayoutNode(t theme.Theme) layout.Node
- func (m Model) Linearize() string
- func (m *Model) Next(validate func() error) error
- func (m Model) Tokens(t theme.Theme) theme.Tokens
- func (m Model) View(t theme.Theme) string
- func (m Model) WithTokens(tok theme.Tokens) Model
Examples ¶
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 holds the ordered step titles and which one is current. Like the rest of this library, it's a plain value the caller stores and mutates via the returned Model — there's no hidden state.
func (Model) LayoutNode ¶
LayoutNode adapts the step bar to a layout.Node, drawn with theme t (as View is). Measure reports its natural size, one row. When the bar is wider than the allotted width, Render scrolls it so the current step is visible. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the steps as plain text for accessible output (see tui.Linearizer): one line per step, "<title>, step K of N, completed", "current" or "upcoming". No connectors or markers.
func (*Model) Next ¶
Next runs validate; if it returns a non-nil error, the step does not advance and the error is returned unchanged. If validate returns nil, the current step advances by one, clamped so it never exceeds the last step index.
func (Model) Tokens ¶
Tokens returns the colour tokens the step bar renders with under t: t's roles, overridden by any theme.WithTokens(theme.ComponentWizard, ...) and then by WithTokens.