prompt

package
v0.0.0-...-f809919 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

tui/prompt/errors.go

Package prompt provides interactive input prompts. All prompts return typed sentinel errors for cancellation and environment-driven refusal; callers check with errors.Is.

tui/prompt/prompt.go

tui/prompt/secret.go

Index

Constants

This section is empty.

Variables

View Source
var ErrAgentMode = errors.New("prompt refused in agent mode")

ErrAgentMode is returned when output.Mode is Agent and no pre-answer was supplied. Callers should branch on a tool-level --yes (or similar) flag before calling a prompt, and only call through when interactive input is actually safe.

View Source
var ErrCancelled = errors.New("prompt cancelled")

ErrCancelled is returned when the user presses Ctrl-C or stdin reaches EOF during a prompt. The terminal mode is restored before this error returns.

View Source
var ErrNoTTY = errors.New("stdin is not a terminal")

ErrNoTTY is returned when stdin is not a terminal and the prompt cannot be satisfied.

Functions

func Confirm

func Confirm(label string, defaultYes bool) (bool, error)

Confirm reads a y/n answer. defaultYes controls the default when the user just presses Enter.

func Prompt

func Prompt(label string) (string, error)

Prompt reads a visible line of input. Returns ErrAgentMode in Agent mode and ErrNoTTY when stdin is not a terminal.

func Secret

func Secret(label string, opts ...SecretOption) (string, error)

Secret reads a password with masked echo by default. Each typed character prints '*' to stderr. Backspace (BS or DEL) erases one character in both buffer and echo. Ctrl-C (0x03) returns ErrCancelled. Enter commits.

Non-TTY stdin → ErrNoTTY. Agent mode → ErrAgentMode.

func Select

func Select(label string, choices []string) (string, error)

Select presents a numbered list and reads the user's 1-based choice, returning the chosen string.

Types

type SecretOption

type SecretOption func(*secretConfig)

SecretOption configures Secret behavior.

func WithNoMask

func WithNoMask() SecretOption

WithNoMask disables the default echoed-asterisk behavior; input is fully silent. Use sparingly — users generally benefit from seeing that keystrokes registered.

Jump to

Keyboard shortcuts

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