interactive

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 5 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 /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, plus its terminal mode: a controlling 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.

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