feat(io): tput capability probe and centralized color escapes#646
Merged
Chemaclass merged 5 commits intomainfrom Apr 29, 2026
Merged
feat(io): tput capability probe and centralized color escapes#646Chemaclass merged 5 commits intomainfrom
Chemaclass merged 5 commits intomainfrom
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #247.
Adopts a hybrid tput + ANSI strategy (see ADR-006): keep ANSI as the primary emission mechanism via the existing
bashunit::sgrhelper, and usetputonly 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 onTERM=dumbor whentput colorsreports fewer than 8. Wired intosrc/colors.shso colors auto-disable when the terminal cannot render them, complementing--no-color/NO_COLOR.bashunit::io::clear_screen— preferstput clear, falls back to\033[2J\033[H. Replaces the hardcoded escape in--watchmode (src/main.sh).src/coverage.sh— hardcoded\033[...mescapes replaced with the central_BASHUNIT_COLOR_*constants. Single source of truth for color emission.No public API changes. Behavior matches status quo on color-capable terminals; on dumb terminals, color now auto-disables instead of emitting raw escapes.