Skip to content

[Console] Design issue with decorator and OutputFormater #10592

@lyrixx

Description

@lyrixx

Current state:

class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
{
    public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
    {
        $outputStream = 'php://stdout';
        if (!$this->hasStdoutSupport()) {
            $outputStream = 'php://output';
        }

        parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);

        $this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
    }
}

As you can see, the $formatter is shared between STDOUT and STDERR ouput. In symfony, everything works fine, but in composer this does not work as the formatter is shared. It does not work in composer because composers overrides the method Application::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 the formatter is decorated. And so their is some color (ansi) on the output. If you execute app/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 for STDOUT (false) and the second time with for STDERR (true).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions