terminal

package
v1.232.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ANSI cursor control sequences.
	EscCarriageReturn = "\r"       // Return cursor to start of line
	EscClearLine      = "\x1b[K"   // Clear from cursor to end of line
	EscResetLine      = "\r\x1b[K" // Return to start and clear entire line
	EscCursorUp       = "\x1b[A"   // Move cursor up one line
	EscCursorDown     = "\x1b[B"   // Move cursor down one line
	EscSaveCursor     = "\x1b[s"   // Save cursor position
	EscRestoreCursor  = "\x1b[u"   // Restore cursor position
)

Variables

This section is empty.

Functions

func HasRealTTYInput added in v1.223.0

func HasRealTTYInput() bool

HasRealTTYInput reports whether stdin is a physical terminal, ignoring --force-tty/ATMOS_FORCE_TTY. Forcing TTY mode can make output render as if a terminal were attached (screenshots, cast recordings), but it cannot conjure an input device — interactive readers (e.g. bubbletea) must not try to open /dev/tty when this returns false.

func IsSpeedLimited added in v1.222.0

func IsSpeedLimited(speed float64) bool

IsSpeedLimited reports whether terminal output should be paced. A speed of 0 means unlimited output, which preserves existing behavior.

func IsTTYWriter added in v1.222.0

func IsTTYWriter(w io.Writer) bool

IsTTYWriter reports whether w is an interactive terminal file.

Types

type ColorProfile

type ColorProfile int

ColorProfile represents terminal color capabilities.

const (
	ColorNone ColorProfile = iota // No color support
	Color16                       // 16 colors (basic ANSI)
	Color256                      // 256 colors
	ColorTrue                     // Truecolor (16 million colors)
)

func (ColorProfile) String

func (c ColorProfile) String() string

String returns the string representation of ColorProfile.

type Config

type Config struct {
	// From CLI flags
	NoColor    bool
	Color      bool
	ForceColor bool
	ForceTTY   bool

	// From environment variables
	EnvNoColor       bool   // NO_COLOR
	EnvCLIColor      string // CLICOLOR
	EnvCLIColorForce bool   // CLICOLOR_FORCE
	EnvTerm          string // TERM
	EnvColorTerm     string // COLORTERM
	EnvCI            bool   // CI

	// From atmos.yaml
	AtmosConfig schema.AtmosConfiguration
}

Config holds terminal configuration from various sources.

func (*Config) DetectColorProfile

func (c *Config) DetectColorProfile(isTTY bool) ColorProfile

DetectColorProfile determines the terminal's color capabilities.

func (*Config) ShouldUseColor

func (c *Config) ShouldUseColor(isTTY bool) bool

ShouldUseColor determines if color should be used based on config priority. Priority (highest to lowest): 1. NO_COLOR or --no-color disables all color. 2. CLICOLOR=0 disables color unless forced. 3. CLICOLOR_FORCE or --force-color forces color even for non-TTY output. 4. --color enables color for TTY output. 5. Atmos terminal settings control color, respecting TTY detection. 6. CI enables color by default. 7. Otherwise use TTY detection.

type IOStream

type IOStream int

IOStream represents an I/O stream type for terminal operations. This mirrors io.Stream but avoids circular dependency.

const (
	// IOStreamData represents stdout (data channel) - value 0.
	IOStreamData IOStream = 0
	// IOStreamUI represents stderr (UI channel) - value 1.
	IOStreamUI IOStream = 1
)

type IOWriter

type IOWriter interface {
	// Write outputs content to the specified stream with automatic masking.
	// stream values: 0=Data (stdout), 1=UI (stderr)
	Write(stream int, content string) error
}

IOWriter is the interface for writing to I/O streams. This avoids circular dependency with pkg/io. The stream parameter uses int to allow different packages to define their own stream types.

type Option

type Option func(*terminal)

Option configures Terminal.

func WithConfig

func WithConfig(cfg *Config) Option

WithConfig sets a custom config (for testing).

func WithIO

func WithIO(io IOWriter) Option

WithIO sets the I/O writer for output. If not set, terminal will write directly to os.Stderr (no masking).

type PacingWriter added in v1.222.0

type PacingWriter struct {
	// contains filtered or unexported fields
}

PacingWriter reveals complete lines at a configured lines-per-second rate. Partial trailing output is buffered until another write completes the line or Close is called.

func NewPacingWriter added in v1.222.0

func NewPacingWriter(writer io.Writer, speed float64) *PacingWriter

NewPacingWriter creates a writer that emits complete lines at speed lines per second.

func (*PacingWriter) Close added in v1.222.0

func (w *PacingWriter) Close() error

Close flushes any buffered partial trailing line immediately.

func (*PacingWriter) Write added in v1.222.0

func (w *PacingWriter) Write(p []byte) (int, error)

type Stream

type Stream int

Stream represents a terminal stream.

const (
	Stdin Stream = iota
	Stdout
	Stderr
)

type Terminal

type Terminal interface {
	// Write outputs UI content to the terminal.
	// Content flows: terminal.Write() → io.Write(UIStream) → masking → stderr
	Write(content string) error

	// IsTTY returns whether the given stream is a TTY.
	IsTTY(stream Stream) bool

	// IsPiped returns whether the given stream is piped to/from another process.
	IsPiped(stream Stream) bool

	// ColorProfile returns the terminal's color capabilities.
	ColorProfile() ColorProfile

	// Width returns the terminal width for the given stream.
	// Returns 0 if width cannot be determined.
	Width(stream Stream) int

	// Height returns the terminal height for the given stream.
	// Returns 0 if height cannot be determined.
	Height(stream Stream) int

	// SetTitle sets the terminal window title (if supported).
	// Does nothing if terminal doesn't support titles or if disabled in config.
	SetTitle(title string)

	// RestoreTitle restores the original terminal title.
	RestoreTitle()

	// Alert emits a terminal bell/alert (if enabled).
	Alert()
}

Terminal provides terminal capability detection and operations. Terminal writes UI output through the I/O layer for automatic masking.

func New

func New(opts ...Option) Terminal

New creates a new Terminal with configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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