Skip to content

feat(text/style): detect terminal color capability via $COLORTERM #75

@rawiriblundell

Description

@rawiriblundell

Background

`text/style.sh` unconditionally emits ANSI color escape sequences with no check
for whether the terminal actually supports them. `$COLORTERM` is the
de-facto environment variable for advertising true color support:

  • `COLORTERM=truecolor` or `COLORTERM=24bit` — terminal supports 24-bit color
  • Unset or other value — assume 8/256 color at most

Proposal

Add a function (e.g. `str_has_truecolor`) that tests `$COLORTERM` and the
`$TERM` value to determine whether true color output is safe. Callers can
use it to decide whether to emit 24-bit escapes (via `text_COLOR_FG_rgb` /
`text_COLOR_BG_rgb`) or fall back to 256-color equivalents.

A broader `str_color_depth` function returning 24, 256, 8, or 0 (no color)
may also be worth considering — covering `$NO_COLOR`, `$TERM=dumb`,
non-interactive shells, and piped output.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions