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
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:
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