Skip to content

Commit

Permalink
[Console] Fix computing column width containing multibyte chars
Browse files Browse the repository at this point in the history
  • Loading branch information
cay89 authored and nicolas-grekas committed Apr 18, 2023
1 parent dccb8d2 commit 79e7e16
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ private function calculateColumnsWidth(iterable $groups)
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
$textLength = Helper::width($textContent);
if ($textLength > 0) {
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
$contentColumns = mb_str_split($textContent, ceil($textLength / $cell->getColspan()));
foreach ($contentColumns as $position => $content) {
$row[$i + $position] = $content;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function renderProvider()
],
new TableSeparator(),
[
new TableCell('Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil!', ['colspan' => 3]),
new TableCell('Cupìdĭtâte díctá âtquè pôrrò, tèmpórà exercitátìónèm mòdí ânìmí núllà nèmò vèl níhìl!', ['colspan' => 3]),
],
],
'default',
Expand All @@ -333,7 +333,7 @@ public function renderProvider()
| 9971-5-0210-0 | A Tale of |
| | Two Cities |
+-------------------------------+-------------------------------+-----------------------------+
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
| Cupìdĭtâte díctá âtquè pôrrò, tèmpórà exercitátìónèm mòdí ânìmí núllà nèmò vèl níhìl! |
+-------------------------------+-------------------------------+-----------------------------+

TABLE
Expand Down

0 comments on commit 79e7e16

Please sign in to comment.