term

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 4 Imported by: 0 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 term holds the canonical terminal-capability primitives: the colour-mode ladder and the TTY check (adr-49, brief invariant 13). It is deliberately banner-independent — the bare-invocation banner (itd-112) is its first consumer and the styled grill (itd-110) its declared second; a surface that wants decoration resolves its mode here rather than minting a parallel copy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal reports whether f is a terminal: the kernel answers a termios get on its descriptor, which is how isatty(3) decides. A character-device test is not enough, because /dev/null is a character device, and stdin redirected from it (or a closed fd 0, which the Go runtime reopens on /dev/null) would read as a person at a terminal. This is the one canonical check; no call site hand-rolls a Stat/ModeCharDevice test.

The descriptor is reached through SyscallConn rather than Fd, so the file keeps its non-blocking mode. A platform without a termios probe here answers false: a consent gate then declines as having no terminal to ask at.

func UTF8Locale

func UTF8Locale(getenv func(string) string) bool

UTF8Locale reports whether the locale advertises UTF-8. Block art (half and shade blocks) assumes UTF-8; without it a decorated surface renders its text lines only. Checked in POSIX order: LC_ALL, LC_CTYPE, LANG.

Types

type ColorMode

type ColorMode int

ColorMode is one rung of the colour ladder.

const (
	// Mono means no colour at all: decoration degrades to plain glyphs,
	// never to blank output.
	Mono ColorMode = iota
	// Ansi16 is the 16-colour floor for colour-capable terminals.
	Ansi16
	// Ansi256 is the xterm-256 palette.
	Ansi256
	// TrueColor is 24-bit colour, rendered straight from hex.
	TrueColor
)

func ResolveColorMode

func ResolveColorMode(getenv func(string) string, noColorFlag bool) ColorMode

ResolveColorMode resolves the ladder for stdout decoration. Precedence, descending: the surface's --no-color flag; the NO_COLOR convention (present AND non-empty — presence alone does not count); TERM dumb or unset (cron, bare containers) forces Mono even when COLORTERM leaks through a multiplexer; COLORTERM truecolor/24bit; a 256color TERM; else the 16-colour floor.

Jump to

Keyboard shortcuts

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