wizard

package module
v0.0.22 Latest Latest
Warning

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

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

README

tinywasm/wizard

Project Badges

A modular, pluggable wizard orchestrator for TinyGo applications.

LLM Context / Core Logic

The library orchestrates a sequence of Step struct helpers. It manages state via a mutable tinywasm/context.

Steps
type Step struct {
    LabelText  string
    DefaultFn  func(ctx *context.Context) string
    OnInputFn  func(input string, ctx *context.Context) (continueFlow bool, err error)
}
Flow Control
  • New(onComplete func(ctx *context.Context), modules ...Module): Initializes orchestration.
  • Change(input): Executes OnInput for the current step.
  • If error != nil, the wizard stays on the current step.
  • If error == nil and continueFlow == true, the wizard advances to the next step.

Features

  • 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 Handler and Loggable patterns.

Usage

// 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")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Step added in v0.0.2

type Step struct {
	LabelText string
	DefaultFn func(ctx *context.Context) string
	OnInputFn func(input string, ctx *context.Context) (continueFlow bool, err error)
	OnShowFn  func(log func(message ...any))
}

Step represents a single interaction or execution unit in the wizard. It is designed to be used as a literal for easy instantiation.

func (*Step) DefaultValue added in v0.0.2

func (s *Step) DefaultValue(ctx *context.Context) string

DefaultValue returns a suggestion based on the current context.

func (*Step) Label added in v0.0.2

func (s *Step) Label() string

Label returns the prompt text for the UI.

func (*Step) OnInput added in v0.0.2

func (s *Step) OnInput(input string, ctx *context.Context) (bool, error)

OnInput executes the step logic using a mutable context.

func (*Step) OnShow added in v0.0.22

func (s *Step) OnShow(log func(message ...any))

OnShow executes optional display logic for the step when it becomes active.

type Wizard

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

Wizard orchestrates the execution of multiple Steps.

func New

func New(onComplete func(ctx *context.Context), items ...any) *Wizard

New creates a wizard from items that provide steps (must implement GetSteps() []*Step).

func (*Wizard) AlwaysShowAllLogs added in v0.0.2

func (w *Wizard) AlwaysShowAllLogs() bool

StreamingLoggable implementation

func (*Wizard) Cancel added in v0.0.2

func (w *Wizard) Cancel()

Cancelable implementation

func (*Wizard) Change added in v0.0.2

func (w *Wizard) Change(newValue string)

func (*Wizard) Label added in v0.0.2

func (w *Wizard) Label() string

func (*Wizard) Name added in v0.0.2

func (w *Wizard) Name() string

func (*Wizard) OnTabActive added in v0.0.22

func (w *Wizard) OnTabActive()

TabAware implementation

func (*Wizard) SetLog added in v0.0.2

func (w *Wizard) SetLog(f func(message ...any))

Loggable implementation

func (*Wizard) Value added in v0.0.2

func (w *Wizard) Value() string

func (*Wizard) WaitingForUser added in v0.0.2

func (w *Wizard) WaitingForUser() bool

Jump to

Keyboard shortcuts

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