terminal#

Utility functions for terminal output.

Functions#

is_tty(→ bool)

Return True if stdout is connected to a TTY.

term_dumb(→ bool)

Return True when TERM indicates a non-capable terminal.

no_color(→ bool)

Return True when color output should be suppressed.

force_color(→ bool)

Return True when color output should be forced even in non-TTY contexts.

should_use_color(→ bool)

Determine whether ANSI color output should be produced.

is_tty() bool#

Return True if stdout is connected to a TTY.

term_dumb() bool#

Return True when TERM indicates a non-capable terminal.

TERM=dumb is the widely-followed terminfo convention for terminals that cannot render any ANSI escape sequences (color, bold, animations). TERM=unknown is treated the same way as a defensive fallback.

no_color() bool#

Return True when color output should be suppressed.

Respects the NO_COLOR standard (https://no-color.org/): color is suppressed when the NO_COLOR environment variable is set to any value. Non-color ANSI formatting (bold, underline, etc.) may still be used.

force_color() bool#

Return True when color output should be forced even in non-TTY contexts.

Respects the FORCE_COLOR environment variable when it is set to a non-empty value.

should_use_color() bool#

Determine whether ANSI color output should be produced.

The precedence order (highest to lowest) is:

  1. NO_COLOR set -> no color.

  2. non-empty FORCE_COLOR set -> color even in non-TTY.

  3. TERM=dumb/TERM=unknown -> no color.

  4. stdout is a TTY -> color.

  5. Otherwise -> no color.