8000 [Console] ConsoleOuput::isDecorated is detected from STDOUT and STDERR by giosh94mhz · Pull Request #13449 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] ConsoleOuput::isDecorated is detected from STDOUT and STDERR #13449

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

giosh94mhz
Copy link
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

In a Symfony command, the OutputInterface has wrong result for isDecorated in this very simple scenario:

 $ app/console vendor:command > output

Here output is a regular file, so $output->isDecorated() should return false, but it returns true. This happen because, the the automatic detection is done on stdout first, and then overridden by a second detection on stderr (which is tty in the example above).

I've added a test which (hopefully) make clear the scenario.

@jakzal jakzal added the Console label Jan 19, 2015
@giosh94mhz giosh94mhz force-pushed the console_ouput_decorated__detected_from_stdout branch 2 times, most recently from 8f59140 to df1ee7f Compare January 22, 2015 10:14
protected function hasColorSupport()
{
// emulate posix_isatty(STDOUT) !== posix_isatty(STDERR)
return ($this->expected = ! parent::hasColorSupport());
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the parenthesis and the space after !?

@giosh94mhz giosh94mhz force-pushed the console_ouput_decorated__detected_from_stdout branch from df1ee7f to 688db71 Compare January 25, 2015 08:12
@giosh94mhz
Copy link
Contributor Author

Removed space and parenthesis, then amended.

@alcohol
Copy link
Contributor
alcohol commented Feb 11, 2015

I think #13661 fixes this? Can you check? :-)

@giosh94mhz
Copy link
Contributor Author

Thank you @alcohol for the ping. I ping in also @Seldaek since helped you with the fix.

Your solutions allow to have a decorated stderr with undecorated stdout, but I still prefer this PR.

The main reason is that the formatter is injected, so it is not a good idea to clone it. The application (not only symfony) may define a non-clonable custom formatter, or a formatter with runtime setting. So I'm 👎 on fixing the bug by cloning, since it is potentially a BC.

That said, I agree with you that stderr should be "promoted" to first class object in console.

The source of the bug is that if you pass null as the $decorated parameters: a double "automatic" detection of "isDecorated" happens, and stderr prevails on stdout.

@Seldaek
Copy link
Member
Seldaek commented Feb 11, 2015

I think there are two possible fixes:

  • the clone as was done in the other PR
  • do the detection on stderr AND stdout and take true only if both are true.

This PR would just do the detection on stdout and IMO it's unacceptable that either stderr or stdout gets colors if they are not capable of receiving them.

@giosh94mhz
Copy link
Contributor Author

do the detection on stderr AND stdout and take true only if both are true.

Your right, assuming that "stdout rules" is not enough. I'll change the commit to handle it as you suggest. Then the decision is up to the maintainers :)

@giosh94mhz giosh94mhz changed the title [Console] ConsoleOuput::isDecorated is detected from STDOUT [Console] ConsoleOuput::isDecorated is detected from STDOUT and STDERR Feb 12, 2015
@giosh94mhz
Copy link
Contributor Author

Ok, I've amended the commit with the changes suggested by @Seldaek .

This is no longer a one-line fix, but there are no BC. The auto-detection is done on both streams and then isDecorated is true only if both are decorated.

@giosh94mhz giosh94mhz force-pushed the console_ouput_decorated__detected_from_stdout branch from 688db71 to e8f300c Compare February 12, 2015 09:29
fabpot added a commit that referenced this pull request Sep 13, 2015
…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             | 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
@fabpot fabpot closed this Sep 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0