Documentation
¶
Index ¶
- Constants
- Variables
- func ActionVerb(text string) string
- func BackLabel() string
- func BackMenuLabel(width int) string
- func CleanupDrafts(targetPath string) error
- func Colorize(text, color string) string
- func DefaultRunSteps(steps []Step) error
- func DraftTargetToken(targetPath string) string
- func DrainStdin()
- 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 IsPlaceholderValue(v any) bool
- func LatestDraftForTarget(targetPath string) string
- func LoadDraftYAML(draftPath string, out any) (bool, error)
- func MultiSelectHint() string
- func NewUserError(message, hint string) error
- func NormalizeChoice(value string) string
- func RestoreTTY()
- func RunSteps(steps []Step, onStepStart func(index, total int, name string), ...) error
- func SelectHint() string
- func WithHint(err error, hint string) error
- func WriteDraft(targetPath string, plaintext []byte) (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 ¶
ActionVerb returns the first word from an action label (after ANSI normalization).
func BackMenuLabel ¶
BackMenuLabel renders a colored Back label aligned like menu entries.
func CleanupDrafts ¶ added in v0.3.0
CleanupDrafts removes all draft files for the given target path.
func Colorize ¶
Colorize wraps a string with an ANSI color code and resets formatting. Pass empty color to keep the text unchanged.
func DefaultRunSteps ¶ added in v0.3.0
DefaultRunSteps executes steps with standard N/M progress formatting. Named steps print "N/M name" on start; a blank line separates non-final steps.
func DraftTargetToken ¶ added in v0.3.0
DraftTargetToken converts a target file path to a safe filename token. Uses path→"__" conversion to preserve directory context. Example: "configs/prod/node.yaml" → "configs__prod__node.yaml"
func DrainStdin ¶ added in v0.3.0
func DrainStdin()
DrainStdin discards bytes pending in stdin (e.g. cursor-position responses left by interactive rendering in raw mode). Safe to call from non-TTY contexts.
func ExitMenuLabel ¶
ExitMenuLabel renders an Exit label aligned like menu entries.
func FormatActionLabel ¶
FormatActionLabel aligns action menus as two columns: verb + description. "Back"/"Exit" remain plain.
func FormatCLIError ¶
FormatCLIError renders a colored CLI error and optional hint.
func FormatMenuLabel ¶
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 ¶
IsBackChoice checks whether a selected value maps to Back.
func IsCancelChoice ¶
IsCancelChoice checks whether a selected value maps to Cancel.
func IsExitChoice ¶
IsExitChoice checks whether a selected value maps to Exit.
func IsInterrupted ¶
IsInterrupted reports whether err is or wraps ErrInterrupted.
func IsPlaceholderValue ¶ added in v0.2.3
IsPlaceholderValue returns true if v is empty, nil, or contains "CHANGE_ME".
func LatestDraftForTarget ¶ added in v0.3.0
LatestDraftForTarget returns the path of the most-recently-modified draft for the given target, or empty string if none exist.
func LoadDraftYAML ¶ added in v0.3.0
LoadDraftYAML reads a draft file and unmarshals it into out. Returns (true, nil) on success, (false, nil) if draftPath is empty, and (false, err) on read or parse failure.
func MultiSelectHint ¶ added in v0.3.0
func MultiSelectHint() string
MultiSelectHint returns the standard keyboard hint for multi-select prompts.
func NewUserError ¶
NewUserError creates a user-facing error message with an optional hint.
func NormalizeChoice ¶
NormalizeChoice strips ANSI colors and trims whitespace for robust comparisons.
func RestoreTTY ¶ added in v0.3.0
func RestoreTTY()
RestoreTTY best-effort restores terminal state. Call from signal handlers or os.Exit paths that bypass deferred term.Restore calls.
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 ¶
func SelectHint() string
SelectHint returns the standard selector help hint used across wizard UIs.
Types ¶
type ManageAction ¶
type ManageAction string
const ( ManageCreate ManageAction = "create" ManageEdit ManageAction = "edit" ManageDelete ManageAction = "delete" ManageSetDefault ManageAction = "set_default" ManageCancel ManageAction = "cancel" )
type ManageOptions ¶
type ManageSelection ¶
type ManageSelection[T any] struct { Action ManageAction Item *T }
func Manage ¶
func Manage[T any](opts ManageOptions[T]) (ManageSelection[T], error)
type ReconcileOptions ¶
type ReconcileOptions struct {
// DropUnknown removes keys not present in template.
DropUnknown bool
// RequiredPaths are dot-notation keys that must exist after reconcile.
RequiredPaths []string
// CheckPlaceholders, when true, checks required paths for empty/CHANGE_ME values.
CheckPlaceholders bool
}
ReconcileOptions controls template sync behavior.
type ReconcileReport ¶
type ReconcileReport struct {
Added []string
Removed []string
MissingRequired []string
PlaceholderValues []string
}
ReconcileReport summarizes changes and validation findings.
func ReconcileWithTemplate ¶
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 ¶
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 ¶
func NewSelector() *Selector
NewSelector creates a Selector with sensible defaults (MaxVisible = 10).
func (*Selector) Confirm ¶ added in v0.3.0
Confirm displays an interactive Y/N prompt. Returns true for yes, false for no. On Ctrl+C, returns false and sets the interrupted flag (check WasInterrupted()). On ESC, returns false (not interrupted). On non-TTY stdin, returns defaultYes without prompting.
func (*Selector) MultiSelect ¶ added in v0.3.0
MultiSelect displays an interactive checkbox list. Arrow keys navigate, Space toggles selection, Enter confirms. Ctrl+C/ESC returns defaults and sets interrupted (Ctrl+C only). Items are returned in original (not selection) order. On non-TTY stdin, returns defaults without prompting.
func (*Selector) Select ¶
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 ¶
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.