term

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package term decides what the CLI may do with the user's terminal: is a stream a TTY, may it carry color, may we prompt. Every package asks here instead of calling isatty itself, so NO_COLOR, CLICOLOR=0 and --no-color are honored everywhere at once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Color

func Color(w io.Writer) bool

Color reports whether w may carry ANSI color and styling.

func IsTerminal

func IsTerminal(w io.Writer) bool

IsTerminal reports whether w is a terminal. Writers that aren't files (test buffers, captured output) are not.

func NoColor

func NoColor() bool

NoColor reports whether color is switched off: --no-color, a non-empty NO_COLOR (https://no-color.org) or CLICOLOR=0.

func QR added in v0.18.0

func QR(text string, maxWidth int) string

QR renders text as a QR code for a terminal: two modules per character row with half-block glyphs, black on a forced white background (ANSI colors) inside the quiet zone scanners need, so it scans the same on dark and light terminal themes. It returns "" when the code can't be encoded or wouldn't fit in maxWidth columns. Callers only use it when colors are on: without them the code could come out inverted.

func SetNoColor

func SetNoColor(v bool)

SetNoColor records --no-color.

func StderrIsTerminal

func StderrIsTerminal() bool

StderrIsTerminal reports whether progress, spinners and hints meant for a person may be written to stderr.

func StdinIsTerminal

func StdinIsTerminal() bool

StdinIsTerminal reports whether the CLI may prompt: stdin is a terminal.

func Width added in v0.18.0

func Width(w io.Writer) int

Width is w's width in columns, or 0 when w isn't a terminal.

Types

type Forced

type Forced struct{ io.Writer }

Forced marks a writer whose reader is known to be a terminal even though the writer itself isn't one, such as the stdin pipe of `less -R`.

Jump to

Keyboard shortcuts

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