wizard

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 2 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(), steps ...*Step): 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. Create steps inline using the exported Step struct
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
        },
    },
}

// 2. Run wizard
wiz := wizard.New(func() { println("Done!") }, steps...)
wiz.Change("new-project")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Module added in v0.0.2

type Module interface {
	Name() string
	GetSteps() []any // Should return []orchestratorStep compatible items
}

Module represents a pluggable component that provides a sequence of steps.

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)
}

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.

type Wizard

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

Wizard orchestrates the execution of multiple Steps.

func New

func New(onComplete func(), steps ...*Step) *Wizard

New creates a generic wizard with the given steps.

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