forms

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package forms provides reusable helpers for building multi-step interactive CLI forms on top of charmbracelet/huh. It adds Escape- to-go-back navigation and a step runner that interprets abort signals as back navigation.

All navigable forms render in the alternate screen buffer so that each step gets a clean display and leaves no residual output in the terminal or scrollback when it completes or is aborted.

Escape returns to the previous step (or cancels if on the first step). Ctrl+C sends SIGINT which terminates the process immediately.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNavigable

func NewNavigable(groups ...*huh.Group) *huh.Form

NewNavigable creates a huh.Form with Escape bound to Quit and rendering in the alternate screen buffer. Each form gets a clean display and leaves no residual output when it completes or is aborted. Pressing Escape causes Run() to return huh.ErrUserAborted, which a Wizard interprets as "go back one step".

func RunStepsWithBack

func RunStepsWithBack(steps []func() error) error

RunStepsWithBack executes a sequence of form step functions with back-navigation support. Prefer Wizard for new code; this function is retained for backward compatibility.

Types

type Wizard

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

Wizard manages a multi-step interactive form flow with Escape-to-go-back navigation. Each step is either a static set of huh.Groups displayed as a single navigable form, or a custom function for dynamic logic.

Build with NewWizard, optionally extend with Group/Step, then call Run.

func NewWizard

func NewWizard(groups ...*huh.Group) *Wizard

NewWizard creates a Wizard whose initial steps are the given groups — each group becomes one navigable form step. For a purely static multi-step flow this is all you need:

err := forms.NewWizard(groupA, groupB, groupC).Run()

For mixed flows, chain Group and Step after the constructor.

func (*Wizard) Group

func (w *Wizard) Group(groups ...*huh.Group) *Wizard

Group adds a step that displays one or more huh groups as a single navigable form. Use this for static form content that doesn't depend on earlier steps.

func (*Wizard) Run

func (w *Wizard) Run() error

Run executes all steps in order with back-navigation support. Escape goes back one step; abort on the first step propagates huh.ErrUserAborted to the caller.

func (*Wizard) Step

func (w *Wizard) Step(fn func() error) *Wizard

Step adds a custom step function for dynamic form logic, such as steps whose content depends on a previous selection or that need to perform setup before prompting.

Jump to

Keyboard shortcuts

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