Documentation
¶
Index ¶
- Constants
- Variables
- func ActionVerb(text string) string
- func BackLabel() string
- func BackMenuLabel(width int) string
- func Colorize(text, color string) string
- func ErrorHint(err error) string
- func ExitLabel() string
- func ExitMenuLabel(width int) string
- func FormatActionLabel(text string, verbWidth int) string
- func FormatCLIError(err error) string
- func FormatMenuLabel(tag, text string, width int) string
- func IsBackChoice(value string) bool
- func IsCancelChoice(value string) bool
- func IsExitChoice(value string) bool
- func IsInterrupted(err error) bool
- func NewUserError(message, hint string) error
- func NormalizeChoice(value string) string
- func RunSteps(steps []Step, onStepStart func(index, total int, name string), ...) error
- func SelectHint() string
- func WithHint(err error, hint string) error
- type ManageAction
- type ManageOptions
- type ManageSelection
- type ReconcileOptions
- type ReconcileReport
- type Selector
- type Session
- type Step
- type UserError
Constants ¶
const ( ANSIReset = "\033[0m" ANSIRed = "\033[31m" ANSIYellow = "\033[33m" ANSICyan = "\033[36m" )
Variables ¶
var ErrInterrupted = errors.New("wizard interrupted")
ErrInterrupted is the shared sentinel used by wizard consumers to propagate Ctrl+C / prompt interruption consistently.
Functions ¶
func ActionVerb ¶ added in v0.2.0
ActionVerb returns the first word from an action label (after ANSI normalization).
func BackLabel ¶ added in v0.2.0
func BackLabel() string
BackLabel returns a consistently colored "Back" label.
func BackMenuLabel ¶ added in v0.2.0
BackMenuLabel renders a colored Back label aligned like menu entries.
func Colorize ¶ added in v0.1.3
Colorize wraps a string with an ANSI color code and resets formatting. Pass empty color to keep the text unchanged.
func ExitLabel ¶ added in v0.2.0
func ExitLabel() string
ExitLabel returns a normalized "Exit" label.
func ExitMenuLabel ¶ added in v0.2.0
ExitMenuLabel renders an Exit label aligned like menu entries.
func FormatActionLabel ¶ added in v0.2.0
FormatActionLabel aligns action menus as two columns: verb + description. "Back"/"Exit" remain plain.
func FormatCLIError ¶ added in v0.1.4
FormatCLIError renders a colored CLI error and optional hint.
func FormatMenuLabel ¶ added in v0.1.3
FormatMenuLabel renders a two-column menu label: [tag] + aligned text. width controls the fixed width for the [tag] column; values <= 0 default to 12.
func IsBackChoice ¶ added in v0.2.0
IsBackChoice checks whether a selected value maps to Back.
func IsCancelChoice ¶ added in v0.2.0
IsCancelChoice checks whether a selected value maps to Cancel.
func IsExitChoice ¶ added in v0.2.0
IsExitChoice checks whether a selected value maps to Exit.
func IsInterrupted ¶ added in v0.2.0
IsInterrupted reports whether err is or wraps ErrInterrupted.
func NewUserError ¶ added in v0.1.4
NewUserError creates a user-facing error message with an optional hint.
func NormalizeChoice ¶ added in v0.2.0
NormalizeChoice strips ANSI colors and trims whitespace for robust comparisons.
func RunSteps ¶
func RunSteps(steps []Step, onStepStart func(index, total int, name string), onStepDone func(index, total int)) error
RunSteps executes steps in order and reports transitions through callbacks.
func SelectHint ¶ added in v0.2.0
func SelectHint() string
SelectHint returns the standard selector help hint used across wizard UIs.
Types ¶
type ManageAction ¶ added in v0.1.3
type ManageAction string
const ( ManageCreate ManageAction = "create" ManageEdit ManageAction = "edit" ManageDelete ManageAction = "delete" ManageSetDefault ManageAction = "set_default" ManageCancel ManageAction = "cancel" )
type ManageOptions ¶ added in v0.1.3
type ManageSelection ¶ added in v0.1.3
type ManageSelection[T any] struct { Action ManageAction Item *T }
func Manage ¶ added in v0.1.3
func Manage[T any](opts ManageOptions[T]) (ManageSelection[T], error)
type ReconcileOptions ¶ added in v0.1.5
type ReconcileOptions struct {
// DropUnknown removes keys not present in template.
DropUnknown bool
// RequiredPaths are dot-notation keys that must exist after reconcile.
RequiredPaths []string
}
ReconcileOptions controls template sync behavior.
type ReconcileReport ¶ added in v0.1.5
ReconcileReport summarizes changes and validation findings.
func ReconcileWithTemplate ¶ added in v0.1.5
func ReconcileWithTemplate(current, template map[string]any, opts ReconcileOptions) (map[string]any, ReconcileReport, error)
ReconcileWithTemplate syncs a config object against a template object. It keeps existing values for keys defined in template, fills missing keys from template defaults, and optionally removes unknown keys.
type Selector ¶ added in v0.2.0
type Selector struct {
// MaxVisible limits items visible at once. 0 means show all.
MaxVisible int
// contains filtered or unexported fields
}
Selector provides an interactive arrow-key selection widget for terminal UIs.
func NewSelector ¶ added in v0.2.0
func NewSelector() *Selector
NewSelector creates a Selector with sensible defaults (MaxVisible = 10).
func (*Selector) Select ¶ added in v0.2.0
Select displays an interactive menu with arrow-key navigation, type-to-filter, and optional scrolling. Returns the selected item. On ESC or Ctrl+C, returns the preferred cancel option (Back > Exit > Cancel) if present, or empty string. Call WasInterrupted() to check for Ctrl+C.
Signature is compatible with ManageOptions.Select.
func (*Selector) WasInterrupted ¶ added in v0.2.0
WasInterrupted returns true if the last Select ended with Ctrl+C.
type Session ¶
type Session struct {
TargetPath string
DraftPath string
State any
IsEmpty func() bool
// contains filtered or unexported fields
}
Session manages a wizard draft lifecycle with pluggable IO handlers.
func NewSession ¶
func NewSession( targetPath, draftPath string, state any, isEmpty func() bool, loadDraftFn func(draftPath string, state any) (bool, error), startFn func(targetPath, draftPath string, state any, isEmpty func() bool) func(), finalizeFn func(targetPath string) error, ) *Session
NewSession creates a reusable wizard session orchestrator.