Skip to content

Table rendering misalignment when using colored/formatted strings in Table component #127

Open
@acataluddi

Description

@acataluddi

Hi Jitendra,

I've discovered a table rendering bug that occurs when using colored/formatted strings. Here's an example with a 2x2
table where values in the last column are in bold:

$rows = [
    ['Name' => 'Server A', 'Hostname' => '<bold>server-a.example.com</end>'],
    ['Name' => 'Server B', 'Hostname' => '<bold>server-b.example.com</end>'],
];

$this->app()->io()->writer()->colors((new Table())->render($rows));

The expected output should be:

+----------+----------------------------------+
| Name     | Hostname                         |
+----------+----------------------------------+
| Server A | server-a.example.com             |
| Server B | server-b.example.com             |
+----------+----------------------------------+

As a result, I get the following:

+----------+----------------------------------+
| Name     | Hostname                         |
+----------+----------------------------------+
| Server A | server-a.example.com |
| Server B | server-b.example.com |
+----------+----------------------------------+

I believe the formatting tags are included in the string length calculation but then removed without being replaced by
trailing white spaces, as the number of missing characters exactly matches strlen('<bold></end>').

Kind regards,

Adriano

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions