Skip to content

[PhpUnitBridge][VarDumper] Fix color detection #53794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

Porting #53707 to VarDumper and tweaking it a bit.

/cc @theofidry FYI

@carsonbot carsonbot added this to the 5.4 milestone Feb 5, 2024
@carsonbot carsonbot changed the title [VarDumper][PhpUnitBridge] Fix color detection [PhpUnitBridge][VarDumper] Fix color detection Feb 5, 2024
}

// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be @\? (not sure if the pcre extension is declared in the composer.json either

Copy link
Member Author

@nicolas-grekas nicolas-grekas Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would it? preg_match doesn't trigger notices unless the regexp is badly formatted, which it isn't
about ext-pcre, we never list it as a requirement - it's one of the builtin extensions.

@nicolas-grekas nicolas-grekas merged commit fa7531f into symfony:5.4 Feb 7, 2024
@nicolas-grekas nicolas-grekas deleted the vd-color branch February 7, 2024 17:54
@@ -403,27 +403,58 @@ private static function hasColorSupport()
return false;
}

if ('Hyper' === getenv('TERM_PROGRAM')) {
if (!self::isTty()) {
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is broken. For not a TTY, it should says false

if ('Hyper' === getenv('TERM_PROGRAM')) {
// Detect msysgit/mingw and assume this is a tty because detection
// does not work correctly, see https://github.com/composer/composer/issues/9690
if (!@stream_isatty($stream) && !\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in this method does not match the logic in the console component. A stream that is not a TTY must not report supporting colors.

nicolas-grekas added a commit that referenced this pull request Feb 8, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

[PhpUnitBridge][VarDumper] fix color detection

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

reworks the logic changes from #53794

Commits
-------

3a09f2f [PhpUnitBridge][VarDumper] fix color detection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants