Skip to content

Table::appendRow() duplicates content once the height of the terminal is reached #29746

@nesk

Description

@nesk

Symfony version(s) affected: 4.1 and 4.2

Description
While appending new rows to a console table, content starts to be duplicated once the height of the table reaches the height of the terminal.

Here's what I get when appending 20 rows in a 15 rows tall terminal
❯ bin/console table
+----+
+----+
| 0  |
+----+
| 0  |
| 1  |
+----+
| 0  |
| 1  |
| 2  |
+----+
| 0  |
| 1  |
| 2  |
| 3  |
+----+
| 0  |
| 1  |
| 2  |
| 3  |
| 4  |
+----+
| 0  |
| 1  |
| 2  |
| 3  |
| 4  |
| 5  |
+----+
| 0  |
| 1  |
| 2  |
| 3  |
| 4  |
| 5  |
| 6  |
| 7  |
| 8  |
| 9  |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
+----+

Here's what I get when appending 20 rows in a 25 rows tall terminal
❯ bin/console table
+----+
| 0  |
| 1  |
| 2  |
| 3  |
| 4  |
| 5  |
| 6  |
| 7  |
| 8  |
| 9  |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
+----+

How to reproduce
Create a new Symfony project: composer create-project symfony/website-skeleton path/to/dir

Create a new file src/Command/TableCommand.php with the following content:

<?php

namespace App\Command;

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

class TableCommand extends Command
{
    protected static $defaultName = 'table';

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $table = new Table($output->section());
        $table->render();

        for ($i = 0 ; $i < 50 ; $i++) {
            $table->appendRow([$i]);
        }
    }
}

Run bin/console table in a terminal with less than 50 rows of height.

Possible Solution
Honestly, I'm not really sure what's happening here so I can 't really help, but I would be glad to provide you with more informations if this bug is specific to my environment.

Additional context
I reproduced this in macOS terminal and iTerm2, but didn't try anywhere else.

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