[Console] Fix table cell styling
This commit is contained in:
parent
11a06ccced
commit
53ecf8393e
@ -109,6 +109,11 @@ abstract class Helper implements HelperInterface
|
||||
}
|
||||
|
||||
public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
|
||||
{
|
||||
return self::strlen(self::removeDecoration($formatter, $string));
|
||||
}
|
||||
|
||||
public static function removeDecoration(OutputFormatterInterface $formatter, $string)
|
||||
{
|
||||
$isDecorated = $formatter->isDecorated();
|
||||
$formatter->setDecorated(false);
|
||||
@ -118,6 +123,6 @@ abstract class Helper implements HelperInterface
|
||||
$string = preg_replace("/\033\[[^m]*m/", '', $string);
|
||||
$formatter->setDecorated($isDecorated);
|
||||
|
||||
return self::strlen($string);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ class Table
|
||||
if (!strstr($cell, "\n")) {
|
||||
continue;
|
||||
}
|
||||
$lines = explode("\n", $cell);
|
||||
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
|
||||
foreach ($lines as $lineKey => $line) {
|
||||
if ($cell instanceof TableCell) {
|
||||
$line = new TableCell($line, array('colspan' => $cell->getColspan()));
|
||||
@ -382,7 +382,7 @@ class Table
|
||||
$nbLines = $cell->getRowspan() - 1;
|
||||
$lines = array($cell);
|
||||
if (strstr($cell, "\n")) {
|
||||
$lines = explode("\n", $cell);
|
||||
$lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
|
||||
$nbLines = count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
|
||||
|
||||
$rows[$line][$column] = new TableCell($lines[0], array('colspan' => $cell->getColspan()));
|
||||
@ -514,6 +514,8 @@ class Table
|
||||
return $this->columnWidths[$column];
|
||||
}
|
||||
|
||||
$lengths = array();
|
||||
|
||||
foreach (array_merge($this->headers, $this->rows) as $row) {
|
||||
if ($row instanceof TableSeparator) {
|
||||
continue;
|
||||
@ -521,9 +523,10 @@ class Table
|
||||
|
||||
foreach ($row as $i => $cell) {
|
||||
if ($cell instanceof TableCell) {
|
||||
$textLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
|
||||
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
|
||||
$textLength = Helper::strlen($textContent);
|
||||
if ($textLength > 0) {
|
||||
$contentColumns = str_split($cell, ceil($textLength / $cell->getColspan()));
|
||||
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
|
||||
foreach ($contentColumns as $position => $content) {
|
||||
$row[$i + $position] = $content;
|
||||
}
|
||||
|
@ -511,6 +511,35 @@ TABLE
|
||||
| Dante Alighieri | J. R. R. Tolkien | J. R. R |
|
||||
+-----------------+------------------+---------+
|
||||
|
||||
TABLE
|
||||
,
|
||||
true,
|
||||
),
|
||||
'Row with formatted cells containing a newline' => array(
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
new TableCell('<error>Dont break'."\n".'here</error>', array('colspan' => 2)),
|
||||
),
|
||||
new TableSeparator(),
|
||||
array(
|
||||
'foo',
|
||||
new TableCell('<error>Dont break'."\n".'here</error>', array('rowspan' => 2)),
|
||||
),
|
||||
array(
|
||||
'bar',
|
||||
),
|
||||
),
|
||||
'default',
|
||||
<<<'TABLE'
|
||||
+-------+------------+
|
||||
[39;49m| [39;49m[37;41mDont break[39;49m[39;49m |[39;49m
|
||||
[39;49m| [39;49m[37;41mhere[39;49m |
|
||||
+-------+------------+
|
||||
[39;49m| foo | [39;49m[37;41mDont break[39;49m[39;49m |[39;49m
|
||||
[39;49m| bar | [39;49m[37;41mhere[39;49m |
|
||||
+-------+------------+
|
||||
|
||||
TABLE
|
||||
,
|
||||
true,
|
||||
|
Reference in New Issue
Block a user