feat(runner): ANSI colors on by default with TTY auto-detection#53
Merged
Conversation
- Add shouldUseAnsi() static method with TTY detection via posix_isatty - Add --no-color global argument (respects no-color.org convention) - Add isAnsi() public method to Runner - Resolution precedence: --no-color > NO_COLOR env > --ansi > TTY detect - Command println/prints now use Runner's resolved ANSI value - Graceful Windows fallback via ANSICON/ConEmuANSI/TERM env checks - ANSI only auto-enables when output stream is StdOut (not in tests) Closes #50
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #53 +/- ##
============================================
- Coverage 87.97% 87.95% -0.03%
- Complexity 1284 1305 +21
============================================
Files 34 34
Lines 3693 3727 +34
============================================
+ Hits 3249 3278 +29
- Misses 444 449 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add hidden: false to all changelog-sections so commits like fix(ci), test:, docs:, refactor:, etc. appear in the changelog.
|
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
Enable ANSI colored output by default when stdout is a TTY, with explicit flags to override.
Motivation
Colors were disabled by default, requiring
--ansievery time. This contradicts CLI conventions — modern tools auto-detect terminal capabilities. Closes #50.Changes
shouldUseAnsi()static method with TTY detection (posix_isatty(STDOUT))--no-colorglobal argument (respects no-color.org convention)isAnsi()public method to RunnerisAnsiEnabled()private method to Command (uses Runner value, falls back to arg check)resolveAnsi()private method — only auto-enables when output isStdOutremoveAnsiArgs()helper to strip--ansi/--no-colorfrom arg arraysrun(), interactive mode, andrunCommand()to handle--no-color--no-colorglobal argument in help outputResolution precedence:
--no-colorflag → OFFNO_COLORenv variable → OFF--ansiflag → ON (force in piped contexts)Platform support:
posix_isatty(STDOUT)ANSICON/ConEmuANSI/TERMenv fallbackHow to Test / Verify
Unit tests with full coverage on reachable code paths:
tests/WebFiori/Tests/Cli/AnsiAutoDetectTest.php(18 tests)RunnerTest.phpfor new global argRun:
composer testBreaking Changes and Migration Steps
Behavioral: terminal output that was previously uncolored now has colors by default. Users who want no colors use
--no-colororNO_COLOR=1.Checklist
composer fix-cs)Related issues
Closes #50