Help us shape the future of Go! Take the 2026 Go Developer Survey

formtest

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package formtest drives real huh forms in tests with no TTY and no production seam (spec 0198 D3). Answers feeds accessible-mode prompts one line per field; Keys feeds the TUI path one key sequence at a time.

Both rest on a reader that yields one chunk per Read: accessible mode reads each field through a fresh buffered reader, so a single reader holding every answer loses all but the first, and the TUI's key parser merges bytes that arrive in one read.

Index

Constants

View Source
const (
	Enter = "\r"
	Down  = "\x1b[B"
	Up    = "\x1b[A"
	Space = " "
	Tab   = "\t"
	Yes   = "y"
	No    = "n"
)

Key sequences for Keys, named for what a person presses.

Variables

This section is empty.

Functions

func AccessibleTTY

func AccessibleTTY(answers io.Reader) props.IO

AccessibleTTY is an IO for a terminal in accessible mode (a screen reader, or TERM=dumb): interactive, so a prompt that is gated on a terminal is reached, and accessible, so it takes Answers. Parallel-safe, unlike the key route.

func Answers

func Answers(lines ...string) io.Reader

Answers is what a person types at accessible-mode prompts, one per field: an option's number for a select, a line for an input, y or n for a confirm. Pair it with an IO whose Accessible reports true.

func Keys

func Keys(seqs ...string) io.Reader

Keys is what a person presses on the TUI path, one sequence per Read, paced so the parser sees each on its own and a field change has happened before the next key. Typed text is one key per rune. The pacing is time, so a test on this route does not call t.Parallel: contention is what makes a paced key land early.

func ProgramOptions

func ProgramOptions(in io.Reader) []tea.ProgramOption

ProgramOptions are the bubbletea options a form on the key route needs: the keys as input, no output, no renderer, a terminal the parser recognises, and a window size, since no renderer means no WindowSizeMsg and a field with a placeholder panics on a negative width.

func TUI

func TUI(keys io.Reader) props.IO

TUI is an IO for the key route: interactive as far as the form is concerned, with the program running headless. The form's own WithProgramOptions receive ProgramOptions.

func TUIForms

func TUIForms(scripts ...io.Reader) props.IO

TUIForms is TUI for a wizard that runs several forms in turn: each In() hands the next script to the next form. A form's program reads its input ahead of the keys it has handled and does not give the surplus back when the form completes, so a later form's keys left on a shared reader are lost with the program that read them. One script per form, in the order the forms run; a form past the last script reads nothing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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