[console][table] adjust width of colspanned cell.

This commit is contained in:
Abdellatif Ait boudad 2016-05-02 12:14:36 +01:00
parent fb92d7a04a
commit 9b35449216
2 changed files with 43 additions and 29 deletions

View File

@ -521,6 +521,18 @@ class Table
continue;
}
foreach ($row as $i => $cell) {
if ($cell instanceof TableCell) {
$textLength = strlen($cell);
if ($textLength > 0) {
$contentColumns = str_split($cell, ceil($textLength / $cell->getColspan()));
foreach ($contentColumns as $position => $content) {
$row[$i + $position] = $content;
}
}
}
}
$lengths[] = $this->getCellWidth($row, $column);
}
@ -550,10 +562,6 @@ class Table
if (isset($row[$column])) {
$cell = $row[$column];
$cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
// we assume that cell value will be across more than one column.
$cellWidth = $cellWidth / $cell->getColspan();
}
return $cellWidth;
}

View File

@ -269,21 +269,27 @@ TABLE
'9971-5-0210-0',
new TableCell("A Tale of \nTwo Cities", array('colspan' => 2)),
),
new TableSeparator(),
array(
new TableCell('Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil!', array('colspan' => 3)),
),
),
'default',
<<<TABLE
+----------------+---------------+-----------------+
| ISBN | Title | Author |
+----------------+---------------+-----------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
+----------------+---------------+-----------------+
| Divine Comedy(Dante Alighieri) |
+----------------+---------------+-----------------+
| Arduino: A Quick-Start Guide | Mark Schmidt |
+----------------+---------------+-----------------+
| 9971-5-0210-0 | A Tale of |
| | Two Cities |
+----------------+---------------+-----------------+
+-------------------------------+-------------------------------+-----------------------------+
| ISBN | Title | Author |
+-------------------------------+-------------------------------+-----------------------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
+-------------------------------+-------------------------------+-----------------------------+
| Divine Comedy(Dante Alighieri) |
+-------------------------------+-------------------------------+-----------------------------+
| Arduino: A Quick-Start Guide | Mark Schmidt |
+-------------------------------+-------------------------------+-----------------------------+
| 9971-5-0210-0 | A Tale of |
| | Two Cities |
+-------------------------------+-------------------------------+-----------------------------+
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
+-------------------------------+-------------------------------+-----------------------------+
TABLE
),
@ -336,16 +342,16 @@ TABLE
),
'default',
<<<TABLE
+------------------+--------+-----------------+
| ISBN | Title | Author |
+------------------+--------+-----------------+
| 9971-5-0210-0 | Dante Alighieri |
| | Charles Dickens |
+------------------+--------+-----------------+
| Dante Alighieri | 9971-5-0210-0 |
| J. R. R. Tolkien | |
| J. R. R | |
+------------------+--------+-----------------+
+------------------+---------+-----------------+
| ISBN | Title | Author |
+------------------+---------+-----------------+
| 9971-5-0210-0 | Dante Alighieri |
| | Charles Dickens |
+------------------+---------+-----------------+
| Dante Alighieri | 9971-5-0210-0 |
| J. R. R. Tolkien | |
| J. R. R | |
+------------------+---------+-----------------+
TABLE
),
@ -473,9 +479,9 @@ TABLE
),
'default',
<<<TABLE
+--+--+--+--+--+--+--+--+--+
| 1 | 2 | 3 | 4 |
+--+--+--+--+--+--+--+--+--+
+---+--+--+---+--+---+--+---+--+
| 1 | 2 | 3 | 4 |
+---+--+--+---+--+---+--+---+--+
TABLE
),