Skip to content

[Console] Section always writes with a newline #37304

@kmadejski

Description

@kmadejski

Symfony version(s) affected: 4.1.0 and higher

Description
ConsoleSectionOutput always writes with a newline even if explicitly set to false, eg.:
$section->write('foo', false); since isDecorated() always returns true by default. Output behaves correctly if $section->setDecorated(false); but all decoration is automatically gone which should not be the case.

How to reproduce

<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestCommand extends Command
{
    protected function configure(): void
    {
        $this->setName('test-command');
        parent::configure();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        /** @var \Symfony\Component\Console\Output\ConsoleOutputInterface $output */
        $section = $output->section();

        for ($i = 0; $i < 100; $i++) {
            $section->write('Element ' . (string) $i, false);
        }

        return 0;
    }
}

Possible Solution
$newline argument value should be taken into account in this method: https://github.com/symfony/console/blob/v4.1.0/Output/ConsoleSectionOutput.php#L97

Once confirmed I'm more than happy to create a PR that fixes it 🙂

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions