Skip to content

feat: modernise colour detection with FORCE_COLOR, COLORTERM and TERM=dumb - #10653

Open
paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:terminal-color-detection
Open

paulbalandan wants to merge 1 commit into
codeigniter4:4.8from
paulbalandan:terminal-color-detection

Conversation

@paulbalandan

Copy link
Copy Markdown
Member

Description
Our colour detection came from composer/xdebug-handler, which has since dropped it. Terminal::hasColorSupport() now follows Symfony's StreamOutput::hasColorSupport(), keeping one difference: a TTY on Unix gets colour whatever its TERM, where Symfony requires TERM to match its pattern.

The checks run in this order:

  1. NO_COLOR turns colour off.
  2. FORCE_COLOR turns it on, even when the output is piped.
  3. A stream that is not a TTY gets no colour, except under MSYS2's MINGW32 and MINGW64.
  4. On Windows, VT100 support turns colour on.
  5. TERM_PROGRAM=Hyper, COLORTERM, ANSICON or ConEmuANSI=ON turns it on.
  6. TERM=dumb turns it off.
  7. Otherwise, colour is on, except that Windows also needs TERM to match Symfony's pattern (xterm*, cygwin*, *-256color and similar).

The variables are read through env(), so they can also be set in .env. NO_COLOR and FORCE_COLOR count only when they are not empty, whatever the value, as no-color.org and force-color.org specify.

Behaviour changes, listed in the changelog:

  • An empty NO_COLOR no longer turns colour off.
  • TERM=dumb turns colour off.
  • On Windows, a stream that is not a TTY no longer gets colour from ANSICON, ConEmu or TERM.
  • On Windows without VT100 support, more TERM values now get colour, where previously only xterm did.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@carson-codeigniter4 carson-codeigniter4 Bot added the 4.8 PRs that target the `4.8` branch. label Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants