-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Use new PHP7.2 functions in hasColorSupport #26910
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more places that check for color support (grep ConEmuANSI src/ -r
)
could you please sync them all?
- src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
- src/Symfony/Component/VarDumper/Dumper/CliDumper.php
Sure. But I could do with some info regarding CliDumper: The constructor checks for Windows color support (so it can set a restricted style set), but only uses environment variables and not the output.
The I was wondering if the output needs to be differentiated, and if so, then what are the criteria for each type. |
Which color set does new versions of Windows support? If it doesn't need the reduced set, then the current logic in the CliDumper constructor should be fine, so that only supportsColors should be updated. |
Windows 10 has supported 24-bit color for over a year now, but you can obviously still run PHP7.2 on earlier versions. |
return function_exists('posix_isatty') && @posix_isatty($this->stream); | ||
if (function_exists('stream_isatty')) { | ||
return @stream_isatty($this->stream); | ||
} elseif (function_exists('posix_isatty')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just if
, not elseif
as the previous case returns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
I've synced DeprecationErrorHandler.php, but without any info about CliDumper.php I have no idea if my changes are correct. I've kept the current logic in the CliDumper constructor, which is not ideal since it won't show 24-bit color output in cmd.exe on Windows 10. Incidentally, the Windows tests pass for me locally, but not on Appveyor for some reason:
I've also added references to the source of the code, but I'll remove them if not considered desirable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with one minor comment.
About the CliDumper constructor, we have to use 16 colors only on some terminals, which is what we do by default. Do you think we can improve the logic and somehow detect when the native Windows terminal supports 24b colors? That's what missing there.
* Reference: Composer\XdebugHandler\Process::supportsColor | ||
* https://github.com/composer/xdebug-handler | ||
* | ||
* @return bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this annotation should be removed and replaced by a return-type on the hasColorsSupport (same in other files below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?? Sorry, you've lost me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups sorry, branch 2.7 doesn't support scalar type hints.
Probably, but I need you to answer my original question: The constructor checks for Windows color support (so it can set a restricted style set), but only uses environment variables and not the output.
|
It is not safe to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(with one minor comment)
*/ | ||
private function isWindowsTrueColor() | ||
{ | ||
$result = strval(getenv('ANSICON_VER')) >= '183' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks to PHP type juggling, this should be simplified to 183 <= getenv('ANSICON_VER')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that is a much better way of doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 9234171
72482c5
to
b0c9225
Compare
Thank you @johnstevenson. |
This PR was squashed before being merged into the 2.7 branch (closes #26910). Discussion ---------- Use new PHP7.2 functions in hasColorSupport | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Fixes bc break in #26609 Reference: https://github.com/composer/xdebug-handler/blob/master/src/Process.php#L111 Commits ------- b0c9225 Use new PHP7.2 functions in hasColorSupport
Thanks for fixing this remaining item, and apologies for not fixing it myself (life/time problem!) |
…ts (chalasr) This PR was merged into the 2.7 branch. Discussion ---------- [HttpKernel] Remove decoration from actual output in tests | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes green again | Fixed tickets | n/a | License | MIT | Doc PR | n/a AppVeyor has color support since #26910, that breaks the build. Fixes it by removing decoration from tested DumpDataCollector CLI outputs, same as what's already done for HTML dumps Commits ------- c4daef9 [VarDumper] Remove decoration from actual output in tests
Fixes bc break in #26609
Reference: https://github.com/composer/xdebug-handler/blob/master/src/Process.php#L111