Skip to content

feat(io): tput capability probe and centralized color escapes#646

Merged
Chemaclass merged 5 commits intomainfrom
feat/247-use-tput-or-similar
Apr 29, 2026
Merged

feat(io): tput capability probe and centralized color escapes#646
Chemaclass merged 5 commits intomainfrom
feat/247-use-tput-or-similar

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

@Chemaclass Chemaclass commented Apr 29, 2026

Summary

Closes #247.

Adopts a hybrid tput + ANSI strategy (see ADR-006): keep ANSI as the primary emission mechanism via the existing bashunit::sgr helper, and use tput only for terminal capability probing and screen clearing — the two places where it actually buys portability without the per-emission failure modes that destabilized prior attempts (PR #245).

  • bashunit::env::supports_color — returns false on TERM=dumb or when tput colors reports fewer than 8. Wired into src/colors.sh so colors auto-disable when the terminal cannot render them, complementing --no-color / NO_COLOR.
  • bashunit::io::clear_screen — prefers tput clear, falls back to \033[2J\033[H. Replaces the hardcoded escape in --watch mode (src/main.sh).
  • src/coverage.sh — hardcoded \033[...m escapes replaced with the central _BASHUNIT_COLOR_* constants. Single source of truth for color emission.
  • ADR-006 documents the decision and rejected alternatives.

No public API changes. Behavior matches status quo on color-capable terminals; on dumb terminals, color now auto-disables instead of emitting raw escapes.

Adopt a hybrid tput + ANSI strategy per ADR-006: keep ANSI as the primary
emission mechanism via the existing bashunit::sgr helper, and use tput for
terminal capability probing and screen clearing.

- Add bashunit::env::supports_color: false on TERM=dumb or when
  tput colors reports fewer than 8.
- Wire supports_color into colors.sh init so colors auto-disable when
  the terminal cannot render them, complementing --no-color / NO_COLOR.
- Add bashunit::io::clear_screen using tput clear with an ANSI fallback;
  replace the hardcoded \033[2J\033[H sequence in --watch mode.
- Replace hardcoded \033[...m escapes in coverage reporting with the
  central _BASHUNIT_COLOR_* constants.

Closes #247
@Chemaclass Chemaclass changed the title feat(io): tput capability probe and centralized color escapes (#247) feat(io): tput capability probe and centralized color escapes Apr 29, 2026
@Chemaclass Chemaclass self-assigned this Apr 29, 2026
@Chemaclass Chemaclass added the enhancement New feature or request label Apr 29, 2026
GitHub Actions runners report TERM=dumb, which made the new tput-based
capability probe disable color globally and broke snapshot/escape-asserting
tests across the CI matrix (same failure mode as PR #245).

Keep bashunit::env::supports_color exposed as a query, but stop wiring it
into colors.sh init. ADR-006 updated to record the deferral and CHANGELOG
adjusted accordingly. Auto-disable will land in a follow-up once a CI-aware
override (CI=true / FORCE_COLOR) is in place and validated on the matrix.
CI runners often have TERM unset, so `tput clear` writes
"tput: No value for \$TERM and no -T specified" to stderr and produces
empty stdout. Capture tput output and only use it when non-empty;
otherwise emit the raw \033[2J\033[H sequence directly.
- Add bashunit::dependencies::has_tput and reuse it from
  bashunit::env::supports_color and bashunit::io::clear_screen,
  matching the existing has_curl / has_wget pattern.
- Extract bashunit::coverage::get_color_for_class to remove the
  duplicated case block in coverage::report_text (per-file row and
  total summary).
- Drop a verbose WHAT comment in coverage.sh now that the constants
  speak for themselves.
@Chemaclass Chemaclass merged commit 75a7ee8 into main Apr 29, 2026
30 checks passed
@Chemaclass Chemaclass deleted the feat/247-use-tput-or-similar branch April 29, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use tput or similar

1 participant