supportsAnsi() returns true unconditionally on anything that is not Windows (src/CLI.php:57-72). It never asks whether STDOUT is actually a terminal, so escape sequences end up in redirected output:
php app list > commands.txt # commands.txt contains \033[0;32m ...
php app list | grep deploy # colors leak into the pipe
The Windows branch already does the right thing by asking sapi_windows_vt100_support(), so the behaviour is inconsistent between platforms.
Two additions worth making:
- Check
stream_isatty(STDOUT) on all platforms and disable ANSI when it is false. The function is already used for STDIN in masked().
- Honour the
NO_COLOR convention (https://no-color.org), which is what CI systems and users set, plus FORCE_COLOR as the escape hatch for when output is piped on purpose.
Rough precedence: explicit setAnsi() call, then FORCE_COLOR, then NO_COLOR, then the TTY check, then the current per-platform detection.
Note that supportsAnsi() carries #[Pure] while already calling getenv(), which is not pure. Worth dropping the attribute here (and on getWidth(), same reason) while touching this.
supportsAnsi()returnstrueunconditionally on anything that is not Windows (src/CLI.php:57-72). It never asks whether STDOUT is actually a terminal, so escape sequences end up in redirected output:The Windows branch already does the right thing by asking
sapi_windows_vt100_support(), so the behaviour is inconsistent between platforms.Two additions worth making:
stream_isatty(STDOUT)on all platforms and disable ANSI when it is false. The function is already used for STDIN inmasked().NO_COLORconvention (https://no-color.org), which is what CI systems and users set, plusFORCE_COLORas the escape hatch for when output is piped on purpose.Rough precedence: explicit
setAnsi()call, thenFORCE_COLOR, thenNO_COLOR, then the TTY check, then the current per-platform detection.Note that
supportsAnsi()carries#[Pure]while already callinggetenv(), which is not pure. Worth dropping the attribute here (and ongetWidth(), same reason) while touching this.