Skip to content
Getting Started

Getting Started

Add prompts and progress to existing command handlers while keeping normal Go control flow. See Alternatives for its strengths and scope. Install with:

go get github.com/nfx/go-tui@latest
Selecting a key and value from a map

Interactive widgets take a context.Context as the first argument: dropdowns, prompts, numbers, multichoices, filepickers, spinners. Tables don’t need a context.

Run the same command in automation

Supply an explicit default when a prompt should also work without a terminal:

environment, err := tui.Dropdown(ctx, "Select environment",
	[]string{"dev", "staging", "prod"}, tui.WithDefault("dev"))

When output is redirected or the command runs in CI, the prompt validates the default and returns it without reading input or printing a prompt. Without a default, this dropdown returns an error wrapping tui.ErrNoTTY; an invalid or ambiguous default wraps tui.ErrInvalidOption. Interactive default behavior depends on the widget: a dropdown can return a unique prefix match immediately. See Dropdowns and non-TTY defaults.

Use tui.Stderr() as your logger’s writer when logs should coexist with widgets on the default terminal. Direct writes to os.Stderr bypass that coordination.

Last updated on