8000 Table Style · Issue #40694 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Table Style #40694

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

Closed
estephanbe opened this issue Apr 3, 2021 · 6 comments
Closed

Table Style #40694

estephanbe opened this issue Apr 3, 2021 · 6 comments

Comments

@estephanbe
Copy link
estephanbe commented Apr 3, 2021

Symfony version(s) affected: 5.2

Description

I'm writing a console app using Symfony Console Component. I'm trying to interact with questions and tables. I want to ask a question and then output a table and then ask another and output another table. All of that happens in the same command class. This is my code:

protected function interact( InputInterface $input, OutputInterface $output ) {
    $this->input     = $input;
    $this->output    = $output;
    $question_helper = $this->getHelper( 'question' );

    $question        = ( new ConfirmationQuestion( 'This is a confirmation question:' ) );
    $question_result = $question_helper->ask( $this->input, $this->output, $question );

    $table = new Table( $this->output );
    $table
    ->setHeaders( array( 'Name', 'Age' ) )
    ->setRows(
        array(
            array( 'Mike', 21 ),
            array( 'Sara', 22 ),
        )
    );
    $table->setStyle( 'box' );
    $table->render();
}

When I'm trying to implement my code, the question works well but when I output the table it shows in a weird way like this:

This is a confirmation question: bla bla
┌──────┬─────└‚ Name │ Age │
├──────┼─────┤
│ Mike │ 21  │
│ Sara │ 22  │
└──────┴─────┘

If I echo the table before the question it works:

┌──────┬─────┐
│ Name │ Age │
├──────┼─────┤
│ Mike │ 21  │
│ Sara │ 22  │
└──────┴─────┘
This is a confirmation question: bla bla

Does anyone have any clue how I can solve this?

This is the complete code:

    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Helper\Table;
    use Symfony\Component\Console\Question\ConfirmationQuestion; // Boolean.
    use Symfony\Component\Console\Helper\TableSeparator;



    class Initialize extends Command {

	protected static $defaultName = 'init';

	public function __construct() {
		parent::__construct();
	}

	protected function configure() {
	}

	protected function interact( InputInterface $input, OutputInterface $output ) {
		$question_helper = $this->getHelper( 'question' );

		$table = new Table( $output );
		$table
		->setHeaders( array( 'Name', 'Age' ) )
		->setRows(
			array(
				array( 'Mike', 21 ),
				( new TableSeparator() ),
				array( 'Sara', 22 ),
			)
		);
		$table->setStyle( 'box' );
		$table->render();

		$question        = ( new ConfirmationQuestion( 'This is a confirmation question:' ) );
		$question_result = $question_helper->ask( $input, $output, $question );


		$table = new Table( $output );
		$table
		->setHeaders( array( 'Name', 'Age' ) )
		->setRows(
			array(
				array( 'Mike', 21 ),
				( new TableSeparator() ),
				array( 'Sara', 22 ),
			)
		);
		$table->setStyle( 'box' );
		$table->render();
	}

	protected function execute( InputInterface $input, OutputInterface $output ) {
		return Command::SUCCESS;
	}
    }

P.S. The IDE encoding is UTF-8. I figured out that the problem is with "$table->setStyle( 'box' );", if I remove this line everything goes normal. If I add this line and change the argument to 'default', everything goes normal too. So, I'm trying to figure out why this line breaks the style.

@Nyholm
Copy link
Member
Nyholm commented Apr 3, 2021

Thank you.

Is this a duplicate of #40634?

@estephanbe
Copy link
Author

Thank you.

Is this a duplicate of #40634?

@Nyholm
Not really. I tried to downgrade to 5.2.5, but the issue is still the same.

@Nyholm
Copy link
Member
Nyholm commented Apr 3, 2021

Okey, thank you for checking.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0