tty

package
v0.68.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 2 Imported by: 0

README

tty Package

The tty package provides TTY (terminal) detection utilities.

Overview

This package exposes two simple functions for checking whether the standard output or error streams are connected to a real terminal. The detection uses golang.org/x/term, which is the same library used by the spinner and progress-bar components in this codebase.

On WebAssembly targets (js/wasm) the package provides stub implementations that always return false, since WASM environments do not have real TTY file descriptors.

Functions

IsStdoutTerminal() bool

Returns true if stdout (os.Stdout) is connected to a terminal.

import "github.com/github/gh-aw/pkg/tty"

if tty.IsStdoutTerminal() {
    // Safe to emit colored or animated output to stdout
}
IsStderrTerminal() bool

Returns true if stderr (os.Stderr) is connected to a terminal.

if tty.IsStderrTerminal() {
    // Safe to emit colored or animated output to stderr
}

Design Notes

  • Terminal detection is evaluated at call time, not cached. This is intentional: the streams could be redirected between calls in some testing scenarios.
  • The WASM stub (tty_wasm.go) always returns false so that components built for the browser never attempt to use ANSI escape codes.
  • Prefer this package over calling term.IsTerminal directly to keep the TTY detection logic centralized and easily testable.
  • Components that need to adapt output for terminals (spinners, progress bars, colored messages) should call IsStderrTerminal() rather than checking os.Stderr directly.

Documentation

Overview

Package tty provides utilities for TTY (terminal) detection. This package uses golang.org/x/term for TTY detection, which aligns with modern Go best practices and the spinner library v1.23.1+ implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsStderrTerminal

func IsStderrTerminal() bool

IsStderrTerminal returns true if stderr is connected to a terminal.

func IsStdoutTerminal

func IsStdoutTerminal() bool

IsStdoutTerminal returns true if stdout is connected to a terminal.

Types

This section is empty.

Jump to

Keyboard shortcuts

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