interactive

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 8 Imported by: 0

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

View Source
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 AgentSubprocessEnvVar added in v0.11.5

func AgentSubprocessEnvVar() string

AgentSubprocessEnvVar returns the first sentinel set in the environment, or "".

func AgentSubprocessEnvVars added in v0.11.5

func AgentSubprocessEnvVars() []string

AgentSubprocessEnvVars returns the sentinel names, for tests to clear.

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):

  1. EnvTestTTY=1 forces interactive ON; any other non-empty value forces OFF.
  2. 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).
  3. Agent sentinels — vendor-set by agent subprocesses.
  4. CI=<non-empty-non-false> — de-facto CI convention.
  5. A Windows console with no window (a desktop app's hidden shell): see console_windows.go.
  6. 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

func IsTerminalReader(r io.Reader) bool

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

func IsTerminalWriter(w io.Writer) bool

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

func ShouldStyle(w io.Writer) bool

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

func OpenPromptTTY() (*PromptTTY, error)

OpenPromptTTY opens the controlling terminal for interactive prompts.

func (*PromptTTY) Close added in v0.11.0

func (t *PromptTTY) Close() error

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

func (t *PromptTTY) Input() *os.File

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

func (t *PromptTTY) Output() *os.File

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.

func (*PromptTTY) Read added in v0.11.0

func (t *PromptTTY) Read(p []byte) (int, error)

Read reads prompt input.

func (*PromptTTY) Write added in v0.11.0

func (t *PromptTTY) Write(p []byte) (int, error)

Write writes prompt output.

Jump to

Keyboard shortcuts

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