A modular, pluggable wizard orchestrator for TinyGo applications.
The library orchestrates a sequence of Step struct helpers. It manages state via a mutable tinywasm/context.
type Step struct {
LabelText string
DefaultFn func(ctx *context.Context) string
OnInputFn func(input string, ctx *context.Context) (continueFlow bool, err error)
}- New(onComplete func(ctx *context.Context), modules ...Module): Initializes orchestration.
- Change(input): Executes
OnInputfor the current step. - If
error != nil, the wizard stays on the current step. - If
error == nilandcontinueFlow == true, the wizard advances to the next step.
- Zero dynamic allocations (fixed capacity context).
- Mutable State: Steps modify the context directly via
ctx.Set(). - Easy Literals: Define steps as simple structs without boilerplate.
- TUI-ready: Implements
HandlerandLoggablepatterns.
// 1. Define a Module
type MyModule struct {
Steps []*wizard.Step
}
func (m MyModule) Name() string { return "My Module" }
func (m MyModule) GetSteps() []any {
steps := make([]any, len(m.Steps))
for i, s := range m.Steps {
steps[i] = s
}
return steps
}
// 2. Create steps
steps := []*wizard.Step{
{
LabelText: "Project Name",
DefaultFn: func(ctx *context.Context) string { return "my-app" },
OnInputFn: func(in string, ctx *context.Context) (bool, error) {
if in == "" { return false, nil }
err := ctx.Set("name", in) // Mutate context in-place
return true, err
},
},
}
// 3. Run wizard
wiz := wizard.New(func(ctx *context.Context) { println("Done!") }, &MyModule{Steps: steps})
wiz.Change("new-project")