Skip to content

Commit

Permalink
respect multi-byte characters when rendering vertical-style tables
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Mar 29, 2024
1 parent 8adc869 commit a2708a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ public function render()
if ($headers && !$containsColspan) {
if (0 === $idx) {
$rows[] = [sprintf(
'<comment>%s</>: %s',
str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
'<comment>%s%s</>: %s',
str_repeat(' ', $maxHeaderLength - Helper::width(Helper::removeDecoration($formatter, $headers[$i] ?? ''))),
$headers[$i] ?? '',
$part
)];
} else {
Expand Down
22 changes: 22 additions & 0 deletions Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,28 @@ public static function provideRenderVerticalTests(): \Traversable
$books,
];

yield 'With multibyte characters in some headers (the "í" in "Títle") and cells (the "í" in "Dívíne")' => [
<<<EOTXT
+-------------------------+
| ISBN: 99921-58-10-7 |
| Títle: Dívíne Comedy |
| Author: Dante Alighieri |
| Price: 9.95 |
+-------------------------+
EOTXT
,
['ISBN', 'Títle', 'Author', 'Price'],
[
[
'99921-58-10-7',
'Dívíne Comedy',
'Dante Alighieri',
'9.95',
],
],
];

yield 'With header for some' => [
<<<EOTXT
+------------------------------+
Expand Down

0 comments on commit a2708a5

Please sign in to comment.