Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 53ecf83

Browse filesBrowse files
committed
[Console] Fix table cell styling
1 parent 11a06cc commit 53ecf83
Copy full SHA for 53ecf83

File tree

3 files changed

+42
-5
lines changed
Filter options

3 files changed

+42
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/Helper.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public static function formatMemory($memory)
109109
}
110110

111111
public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
112+
{
113+
return self::strlen(self::removeDecoration($formatter, $string));
114+
}
115+
116+
public static function removeDecoration(OutputFormatterInterface $formatter, $string)
112117
{
113118
$isDecorated = $formatter->isDecorated();
114119
$formatter->setDecorated(false);
@@ -118,6 +123,6 @@ public static function strlenWithoutDecoration(OutputFormatterInterface $formatt
118123
$string = preg_replace("/\033\[[^m]*m/", '', $string);
119124
$formatter->setDecorated($isDecorated);
120125

121-
return self::strlen($string);
126+
return $string;
122127
}
123128
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/Table.php
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private function buildTableRows($rows)
341341
if (!strstr($cell, "\n")) {
342342
continue;
343343
}
344-
$lines = explode("\n", $cell);
344+
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
345345
foreach ($lines as $lineKey => $line) {
346346
if ($cell instanceof TableCell) {
347347
$line = new TableCell($line, array('colspan' => $cell->getColspan()));
@@ -382,7 +382,7 @@ private function fillNextRows($rows, $line)
382382
$nbLines = $cell->getRowspan() - 1;
383383
$lines = array($cell);
384384
if (strstr($cell, "\n")) {
385-
$lines = explode("\n", $cell);
385+
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
386386
$nbLines = count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
387387

388388
$rows[$line][$column] = new TableCell($lines[0], array('colspan' => $cell->getColspan()));
@@ -514,16 +514,19 @@ private function getColumnWidth($column)
514514
return $this->columnWidths[$column];
515515
}
516516

517+
$lengths = array();
518+
517519
foreach (array_merge($this->headers, $this->rows) as $row) {
518520
if ($row instanceof TableSeparator) {
519521
continue;
520522
}
521523

522524
foreach ($row as $i => $cell) {
523525
if ($cell instanceof TableCell) {
524-
$textLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
526+
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
527+
$textLength = Helper::strlen($textContent);
525528
if ($textLength > 0) {
526-
$contentColumns = str_split($cell, ceil($textLength / $cell->getColspan()));
529+
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
527530
foreach ($contentColumns as $position => $content) {
528531
$row[$i + $position] = $content;
529532
}

‎src/Symfony/Component/Console/Tests/Helper/TableTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/TableTest.php
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,35 @@ public function renderProvider()
511511
| Dante Alighieri | J. R. R. Tolkien | J. R. R |
512512
+-----------------+------------------+---------+
513513
514+
TABLE
515+
,
516+
true,
517+
),
518+
'Row with formatted cells containing a newline' => array(
519+
array(),
520+
array(
521+
array(
522+
new TableCell('<error>Dont break'."\n".'here</error>', array('colspan' => 2)),
523+
),
524+
new TableSeparator(),
525+
array(
526+
'foo',
527+
new TableCell('<error>Dont break'."\n".'here</error>', array('rowspan' => 2)),
528+
),
529+
array(
530+
'bar',
531+
),
532+
),
533+
'default',
534+
<<<'TABLE'
535+
+-------+------------+
536+
| Dont break |
537+
| here |
538+
+-------+------------+
539+
| foo | Dont break |
540+
| bar | here |
541+
+-------+------------+
542+
514543
TABLE
515544
,
516545
true,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.