-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Design issue with decorator and OutputFormater #10592
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
Comments
is this issue related bldr-io/bldr#115 ? We actually want to output color. Currently we see the ->getOutput is getting us no colors when there should be. Any hint? cc/ @romainneutron |
may be. The initial issue was in composer. |
@lyrixx yes, but your issue is that you did not have color or that you did have color when you shouldn't have? My issue is that I am doing $output = $this->getOutput();
$process->start(
function ($type, $buffer) use ($output) {
$output->write($buffer);
}
);
while ($process->isRunning()) {
} and getting no color |
don't remember |
@lyrixx I got some light shed on my problem, it is more related to phpspec and behat because phpunit does output with color without problems when i run it inside my process. What i am wondering is why Process output gets stripped of these colors when i output it. What is phpspec or behat doing differently is that they are based on Symfony App console one way or the other, so this emphasizes the fact that something is very wrong... 🐱 |
nvm i guess it was all in the guessing on the colors inside a process --colors solved it 👍 |
Yeah, the reason PHPUnit gives you colors is because it does not care whether your console supports colors. If you configure it with colors and they are not supported, you will just get an ugly output because of the ANSI sequences being displayed. |
well the only problem on my side was that i was running bldr, bldr in itself gives you colors, however it wraps in a subprocess the execution of its calls which could be phpspec or behat. So I was not passing --ansi or --colors to force them so there was no color on their outputs. When I did force it with these flag options on the calls then voila i started to get colors 👍 . I think the initial problem for when @lyrixx was wrapping a cli application with the app console component is still valid and more of a design problem than what I was talking about. And still valid. |
I think a possible fix to this issue is:
|
Workaround to this issue User way
Dev way :
|
Related #13661 |
…corated when both stderr and stdout support colors (Seldaek) This PR was merged into the 2.3 branch. Discussion ---------- [Console] Ensure the console output is only detected as decorated when both stderr and stdout support colors | Q 6AB4 | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10592 #13449 | License | MIT | Doc PR | This is a simplified version of #13661 which does not create any issues with having two decorators but merely ensures that if either STDERR **or** STDOUT has colors disabled, then both will have decoration disabled. It's not a perfect solution but it's better than having both enabled as this breaks things. And I don't think we can come to a better solution without api changes. Commits ------- f3d8444 [Console] Ensure the console output is only detected as decorated when both stderr and stdout support colors
Current state:
As you can see, the
$formatter
is shared betweenSTDOUT
andSTDERR
ouput. In symfony, everything works fine, but in composer this does not work as theformatter
is shared. It does not work in composer because composers overrides the methodApplication::run
. (ref).So, if you ran
composer | cat -
,STDOUT
is not a tty. But symfony and/or composer thinks STDOUT is a tty. And so theformatter
isdecorated
. And so their is some color (ansi) on the output. If you executeapp/console | cat -
, their is not color on the output, which is the good behavior.This happen in composer because
Formatter->setDecorated()
is called twice, the first time forSTDOUT
(false
) and the second time with forSTDERR
(true
).The text was updated successfully, but these errors were encountered: