Documentation
¶
Overview ¶
Package ugh is a Go testing library for driving huh terminal UI forms through raw I/O streams using a virtual terminal emulator.
Index ¶
- Variables
- func Affirm(r *Response)
- func PressEnter(r *Response)
- func Reject(r *Response)
- type Action
- type Console
- func (c *Console) Expect(m Matcher) *Expectation
- func (c *Console) Run(ctx context.Context, appOutput io.Reader, appInput io.Writer)
- func (c *Console) Screen() string
- func (c *Console) Send(key Key) *Console
- func (c *Console) SendText(text string) *Console
- func (c *Console) Start(ctx context.Context, appOutput io.Reader, appInput io.Writer) func()
- type Expectation
- type Key
- type Matcher
- func Confirm(title string) Matcher
- func ConfirmRegexp(pattern string) Matcher
- func Input(title string) Matcher
- func MatchScreen(desc string, fn func(screen string) bool) Matcher
- func MultiSelect(title string) Matcher
- func Note(title string) Matcher
- func Regexp(pattern string) Matcher
- func Select(title string) Matcher
- func SelectRegexp(pattern string) Matcher
- func String(s string) Matcher
- func Text(title string) Matcher
- type Option
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( Enter = Key{/* contains filtered or unexported fields */} Tab = Key{/* contains filtered or unexported fields */} ShiftTab = Key{/* contains filtered or unexported fields */} Up = Key{/* contains filtered or unexported fields */} Down = Key{/* contains filtered or unexported fields */} Right = Key{/* contains filtered or unexported fields */} Left = Key{/* contains filtered or unexported fields */} Space = Key{/* contains filtered or unexported fields */} Escape = Key{/* contains filtered or unexported fields */} Backspace = Key{/* contains filtered or unexported fields */} CtrlC = Key{/* contains filtered or unexported fields */} CtrlA = Key{/* contains filtered or unexported fields */} CtrlE = Key{/* contains filtered or unexported fields */} CtrlU = Key{/* contains filtered or unexported fields */} CtrlK = Key{/* contains filtered or unexported fields */} CtrlW = Key{/* contains filtered or unexported fields */} Home = Key{/* contains filtered or unexported fields */} End = Key{/* contains filtered or unexported fields */} Delete = Key{/* contains filtered or unexported fields */} )
Pre-defined key constants encoded as ANSI byte sequences compatible with bubbletea v2's ultraviolet input parser.
Functions ¶
Types ¶
type Action ¶
type Action func(r *Response)
Action is a function that runs at execution time after an expectation matches. It receives a *Response providing access to the screen state and the ability to send keystrokes.
func SelectIndex ¶
SelectIndex returns an Action that sends Down×n then Enter. For Select fields, selecting by 0-based index.
func SelectOption ¶
SelectOption returns an Action that parses the screen to find the option label, navigates with Up/Down, then sends Enter. Uses Response.Text() as the field title for screen parsing.
func ToggleIndices ¶
ToggleIndices returns an Action that navigates to each index and sends Space to toggle, then Enter to submit. For MultiSelect fields.
func ToggleOptions ¶
ToggleOptions returns an Action that navigates to each label and sends Space to toggle, then Enter to submit. For MultiSelect fields.
func TypeMultiline ¶
TypeMultiline returns an Action that types text and sends Tab. For Text fields, where Enter inserts newlines and Tab advances to the next field.
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console drives a huh form through a virtual terminal emulator. Interactions are recorded as a chain of expectations and actions, then executed via Run or Start.
A t.Cleanup hook is registered automatically to verify that all recorded expectations were executed. If expectations are registered but Run/Start is never called, or if some expectations remain pending after execution, the test fails.
func New ¶
New creates a new test console. The testing.TB is used for failure reporting. A t.Cleanup hook is registered to verify all expectations are fulfilled.
func (*Console) Expect ¶
func (c *Console) Expect(m Matcher) *Expectation
Expect records a screen expectation using the given Matcher and returns an *Expectation for attaching actions via Do or further chaining.
func (*Console) Run ¶
Run executes all recorded steps synchronously against the application's I/O streams. Calls t.Fatalf on failure.
func (*Console) Screen ¶
Screen returns the current virtual terminal screen contents as plain text. Safe to call at any time, including during Run from other goroutines or after Run completes. Returns an empty string if called before Run.
func (*Console) Send ¶
Send records a step that sends a single key's ANSI byte sequence to the application's stdin. Returns *Console for chaining.
func (*Console) SendText ¶
SendText records a step that types text as individual characters with an inter-key delay. Returns *Console for chaining.
type Expectation ¶
type Expectation struct {
// contains filtered or unexported fields
}
Expectation represents a pending screen expectation that can be completed with Do.
func (*Expectation) Do ¶
func (e *Expectation) Do(action Action) *Expectation
Do attaches an action to run when the expectation matches and returns the Expectation for further chaining.
func (*Expectation) Expect ¶
func (e *Expectation) Expect(m Matcher) *Expectation
Expect chains another expectation after this one.
func (*Expectation) Send ¶
func (e *Expectation) Send(key Key) *Expectation
Send records a keystroke step and returns the Expectation for chaining.
func (*Expectation) SendText ¶
func (e *Expectation) SendText(text string) *Expectation
SendText records a text-typing step and returns the Expectation for chaining.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key represents a keystroke as an ANSI byte sequence.
type Matcher ¶
Matcher describes what to wait for on screen. Implement this interface to create custom matchers for use with Console.Expect.
func ConfirmRegexp ¶
ConfirmRegexp creates a regexp Matcher for a huh Confirm field title.
func MatchScreen ¶
MatchScreen creates a Matcher from a description and a predicate function.
func MultiSelect ¶
MultiSelect creates a substring Matcher for a huh MultiSelect field title.
func SelectRegexp ¶
SelectRegexp creates a regexp Matcher for a huh Select field title.
type Option ¶
type Option func(*Console)
Option configures a Console.
func WithTimeout ¶
WithTimeout sets the per-step timeout for expect operations. Default: 10s.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response provides the action function with screen state and keystroke sending.
func (*Response) Screen ¶
Screen returns the virtual terminal screen contents at the moment the expectation matched.