{"modulePath":"github.com/kernel/cli","version":"v0.54.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package interactive\n\nPackage interactive owns every interactive prompt in the CLI: it detects whether stdin is attached to a terminal, executes pterm confirm/select/text prompts when it is, and fails fast with actionable errors when it is not.\n\nInteractive prompts read keystrokes from the terminal. In a non-interactive shell — an AI agent's bash tool, CI, or any piped stdin — they never return (the underlying keyboard listener spins forever), so prompt execution is centralized here behind the TTY gate. Command code must prompt through a Prompter (or the package-level helpers backed by the default Prompter) instead of pterm's interactive printers; no direct pterm interactive calls should exist outside this package.\n\n## Functions\n\n```go\nfunc Confirm(action, promptText string) (bool, error)\n```\nConfirm is Prompter.Confirm on the default (ambient-stdin) Prompter, for command code without an injected Prompter.\n\n```go\nfunc ErrConfirmationRequired(action string) error\n```\nErrConfirmationRequired builds the fail-fast error for confirmation prompts. action describes what would have been confirmed, e.g. \"delete profile 'foo'\". The resulting error tells the caller (often an AI agent) to re-run with --yes.\n\n```go\nfunc ErrInputRequired(what, hint string) error\n```\nErrInputRequired builds the fail-fast error for a single text/select prompt. what describes the input that would have been prompted for, e.g. \"app name\"; hint names the flag(s) to pass instead, e.g. \"pass --name to set the app name\".\n\n```go\nfunc ErrInputsRequired(problems []string) error\n```\nErrInputsRequired builds the fail-fast error for one or more missing or invalid inputs. Commands with several promptable inputs should validate them all up front and report every problem in a single error, so a non-interactive caller can fix everything in one retry instead of discovering problems one invocation at a time.\n\n```go\nfunc IsInteractive() bool\n```\nIsInteractive reports whether stdin is attached to a terminal, i.e. whether interactive prompts can be shown. Equivalent to NewPrompter().CanPrompt().\n\n```go\nfunc Select(what, hint, promptText string, options []string) (string, error)\n```\nSelect is Prompter.Select on the default (ambient-stdin) Prompter, for command code without an injected Prompter.\n\n```go\nfunc TextInput(what, hint, promptText string) (string, error)\n```\nTextInput is Prompter.TextInput on the default (ambient-stdin) Prompter, for command code without an injected Prompter.\n\n## Types\n\n```go\ntype PromptError struct {\n\t// What names what would have been prompted for, e.g. \"input\" or\n\t// \"confirmation to delete profile 'foo'\".\n\tWhat string\n\t// Problems lists the fixes, e.g. \"--name is required\" or \"re-run with\n\t// --yes to skip the confirmation prompt\". Always at least one entry.\n\tProblems []string\n}\n```\nPromptError is returned instead of showing an interactive prompt when stdin is not a terminal. It carries every problem the caller must fix so a single retry can succeed. The CLI's top-level error handler renders it via Display without width-based re-wrapping, so flag tokens such as --yes or --template are never split across lines.\n\n```go\nfunc (e *PromptError) Display() string\n```\nDisplay renders the problems for terminal output, one per line, so each fix instruction stays an intact, greppable token sequence regardless of terminal width.\n\n```go\nfunc (e *PromptError) Error() string\n```\nError renders the problems inline on a single line, following the Go convention that error strings do not contain newlines.\n\n```go\ntype Prompter struct {\n\t// contains filtered or unexported fields\n}\n```\nPrompter executes interactive prompts against a terminal capability. Each value owns its capability — there is no package-level mutable state — so tests can construct a Prompter with a fixed capability without affecting other goroutines or invocations.\n\nThe zero value is equivalent to NewPrompter(): it detects the terminal from stdin at prompt time.\n\n```go\nfunc NewPrompter() Prompter\n```\nNewPrompter returns a Prompter that detects terminal capability from stdin at prompt time.\n\n```go\nfunc NewPrompterWithTerminal(isTTY bool) Prompter\n```\nNewPrompterWithTerminal returns a Prompter with a fixed terminal capability. Tests use NewPrompterWithTerminal(false) to exercise the fail-fast paths deterministically, regardless of the harness's stdin.\n\n```go\nfunc (p Prompter) CanPrompt() bool\n```\nCanPrompt reports whether this Prompter can show interactive prompts.\n\n```go\nfunc (p Prompter) Confirm(action, promptText string) (bool, error)\n```\nConfirm shows a yes/no confirmation prompt with the given prompt text and reports the choice. When the Prompter cannot prompt it fails fast with ErrConfirmationRequired(action) instead.\n\n```go\nfunc (p Prompter) Select(what, hint, promptText string, options []string) (string, error)\n```\nSelect shows a select prompt over options and returns the chosen option. When the Prompter cannot prompt it fails fast with ErrInputRequired(what, hint) instead.\n\n```go\nfunc (p Prompter) TextInput(what, hint, promptText string) (string, error)\n```\nTextInput shows a free-text prompt and returns the entered text. When the Prompter cannot prompt it fails fast with ErrInputRequired(what, hint) instead.\n\n","path":"github.com/kernel/cli/pkg/interactive","name":"interactive","synopsis":"Package interactive owns every interactive prompt in the CLI: it detects whether stdin is attached to a terminal, executes pterm confirm/select/text prompts when it is, and fails fast with actionable errors when it is not.","isRedistributable":true}
