Skip to content

Commit 56e8692

Browse files
VincentLangletnicolas-grekas
authored andcommitted
[Console] Fix display of Table on Windows OS
1 parent ed7d7aa commit 56e8692

File tree

1 file changed

+6
-4
lines changed
  • src/Symfony/Component/Console/Helper

1 file changed

+6
-4
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,10 @@ private function buildTableRows(array $rows): TableRows
621621
if (!strstr($cell ?? '', "\n")) {
622622
continue;
623623
}
624-
$escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell)));
624+
$eol = str_contains($cell ?? '', "\r\n") ? "\r\n" : "\n";
625+
$escaped = implode($eol, array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode($eol, $cell)));
625626
$cell = $cell instanceof TableCell ? new TableCell($escaped, ['colspan' => $cell->getColspan()]) : $escaped;
626-
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default></>\n", $cell));
627+
$lines = explode($eol, str_replace($eol, '<fg=default;bg=default></>'.$eol, $cell));
627628
foreach ($lines as $lineKey => $line) {
628629
if ($colspan > 1) {
629630
$line = new TableCell($line, ['colspan' => $colspan]);
@@ -685,8 +686,9 @@ private function fillNextRows(array $rows, int $line): array
685686
$nbLines = $cell->getRowspan() - 1;
686687
$lines = [$cell];
687688
if (strstr($cell, "\n")) {
688-
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
689-
$nbLines = \count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
689+
$eol = str_contains($cell, "\r\n") ? "\r\n" : "\n";
690+
$lines = explode($eol, str_replace($eol, '<fg=default;bg=default>'.$eol.'</>', $cell));
691+
$nbLines = \count($lines) > $nbLines ? substr_count($cell, $eol) : $nbLines;
690692

691693
$rows[$line][$column] = new TableCell($lines[0], ['colspan' => $cell->getColspan(), 'style' => $cell->getStyle()]);
692694
unset($lines[0]);

0 commit comments

Comments
 (0)