Documentation
¶
Overview ¶
Package interactive provides TTY-related helpers shared between the cli and strategy packages without inducing an import cycle (strategy cannot import cli).
Index ¶
Constants ¶
const EnvTestTTY = "ENTIRE_TEST_TTY"
EnvTestTTY is the env-var name for the force-interactive test override.
- EnvTestTTY=1 → CanPromptInteractively returns true.
- EnvTestTTY set to any other value → returns false.
- EnvTestTTY unset → real detection via testing.Testing(), agent sentinels, CI, then a platform-specific controlling-terminal probe.
Variables ¶
This section is empty.
Functions ¶
func CanPromptInteractively ¶
func CanPromptInteractively() bool
CanPromptInteractively reports whether interactive confirmation prompts (huh forms, yes/no questions, etc.) can be shown. Returns false in CI, agent subprocesses that inherit a TTY but can't respond to prompts, and other environments without a controlling TTY.
Precedence (first match wins):
- EnvTestTTY=1 forces interactive ON; any other non-empty value forces OFF.
- testing.Testing() — `go test` runs default to OFF so in-process tests don't hang on developer terminals that have a real controlling terminal. Subprocess tests must spawn via execx.NonInteractive (or set EnvTestTTY).
- Agent sentinels — vendor-set by agent subprocesses.
- CI=<non-empty-non-false> — de-facto CI convention.
- Platform-specific controlling-terminal probe, plus its terminal mode on platforms that expose one: a terminal held in raw mode belongs to a full-screen TUI (lazygit, gitui, tig, …) that spawned us, not to a shell we can prompt. See rawmode_unix.go and rawmode_windows.go.
func IsTerminalReader ¶ added in v0.9.0
IsTerminalReader reports whether r is an *os.File backed by a terminal. It is useful when an explicitly interactive command needs to distinguish a human at stdin from an agent process that merely inherited a controlling TTY.
func IsTerminalWriter ¶
IsTerminalWriter reports whether w is an *os.File backed by a terminal. Use for deciding on color, pager, progress bars, or other writer-scoped TTY formatting. For "can I prompt the user?" use CanPromptInteractively.
func ShouldStyle ¶ added in v0.7.6
ShouldStyle reports whether ANSI-styled output (color, bold, rendered markdown) should be written to w. It is the single gate for writer-scoped styling decisions: NO_COLOR disables styling per https://no-color.org, legacy consoles that can't handle ANSI escapes are excluded, and otherwise the answer is whether w is a terminal.
func UnderTest ¶ added in v0.6.0
func UnderTest() bool
UnderTest reports whether the process is running in a test context — either inside `go test` (testing.Testing()) or with EnvTestTTY explicitly set. Use to skip operations that read from the real controlling terminal even when CanPromptInteractively() returns true.
Types ¶
type PromptTTY ¶ added in v0.11.0
type PromptTTY struct {
// contains filtered or unexported fields
}
PromptTTY is the platform's controlling terminal, opened for prompt input and output independently where the platform requires separate handles.
func OpenPromptTTY ¶ added in v0.11.0
OpenPromptTTY opens the controlling terminal for interactive prompts.
func (*PromptTTY) Close ¶ added in v0.11.0
Close closes the prompt terminal handles. A read still pending on the input is released first: os.File.Close waits for it, and on Windows a console read only completes on a keypress, so a prompt whose reader loop had already issued its next read (Bubble Tea's, after the answer) would otherwise make the user press a key a second time. See releasePendingReads. A release failure is reported alongside the close, never instead of it: the handles are closed regardless.
func (*PromptTTY) Input ¶ added in v0.11.0
Input returns the terminal input handle. Callers that hand terminal input to a library such as Bubble Tea need the concrete file so it can manage raw mode.
func (*PromptTTY) Output ¶ added in v0.11.0
Output returns the terminal output handle. Callers that hand terminal output to a library such as Bubble Tea need the concrete file so it can enable the console's VT processing.