Help us shape the future of Go! Take the 2026 Go Developer Survey

interactive

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 4 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 = "TRACE_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 /dev/tty 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):

  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 happen to have a real /dev/tty. 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. /dev/tty probe.

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 UnderTest

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 terminal (e.g. opening /dev/tty) even when CanPromptInteractively() returns true.

Types

This section is empty.

Jump to

Keyboard shortcuts

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