[console][table] adjust width of colspanned cell.
This commit is contained in:
parent
fb92d7a04a
commit
9b35449216
@ -521,6 +521,18 @@ class Table
|
|||||||
continue;
|
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);
|
$lengths[] = $this->getCellWidth($row, $column);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,10 +562,6 @@ class Table
|
|||||||
if (isset($row[$column])) {
|
if (isset($row[$column])) {
|
||||||
$cell = $row[$column];
|
$cell = $row[$column];
|
||||||
$cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
|
$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;
|
return $cellWidth;
|
||||||
}
|
}
|
||||||
|
@ -269,21 +269,27 @@ TABLE
|
|||||||
'9971-5-0210-0',
|
'9971-5-0210-0',
|
||||||
new TableCell("A Tale of \nTwo Cities", array('colspan' => 2)),
|
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',
|
'default',
|
||||||
<<<TABLE
|
<<<TABLE
|
||||||
+----------------+---------------+-----------------+
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
| ISBN | Title | Author |
|
| ISBN | Title | Author |
|
||||||
+----------------+---------------+-----------------+
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
|
||||||
+----------------+---------------+-----------------+
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
| Divine Comedy(Dante Alighieri) |
|
| Divine Comedy(Dante Alighieri) |
|
||||||
+----------------+---------------+-----------------+
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
| Arduino: A Quick-Start Guide | Mark Schmidt |
|
| Arduino: A Quick-Start Guide | Mark Schmidt |
|
||||||
+----------------+---------------+-----------------+
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
| 9971-5-0210-0 | A Tale of |
|
| 9971-5-0210-0 | A Tale of |
|
||||||
| | Two Cities |
|
| | Two Cities |
|
||||||
+----------------+---------------+-----------------+
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
|
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
|
||||||
|
+-------------------------------+-------------------------------+-----------------------------+
|
||||||
|
|
||||||
TABLE
|
TABLE
|
||||||
),
|
),
|
||||||
@ -336,16 +342,16 @@ TABLE
|
|||||||
),
|
),
|
||||||
'default',
|
'default',
|
||||||
<<<TABLE
|
<<<TABLE
|
||||||
+------------------+--------+-----------------+
|
+------------------+---------+-----------------+
|
||||||
| ISBN | Title | Author |
|
| ISBN | Title | Author |
|
||||||
+------------------+--------+-----------------+
|
+------------------+---------+-----------------+
|
||||||
| 9971-5-0210-0 | Dante Alighieri |
|
| 9971-5-0210-0 | Dante Alighieri |
|
||||||
| | Charles Dickens |
|
| | Charles Dickens |
|
||||||
+------------------+--------+-----------------+
|
+------------------+---------+-----------------+
|
||||||
| Dante Alighieri | 9971-5-0210-0 |
|
| Dante Alighieri | 9971-5-0210-0 |
|
||||||
| J. R. R. Tolkien | |
|
| J. R. R. Tolkien | |
|
||||||
| J. R. R | |
|
| J. R. R | |
|
||||||
+------------------+--------+-----------------+
|
+------------------+---------+-----------------+
|
||||||
|
|
||||||
TABLE
|
TABLE
|
||||||
),
|
),
|
||||||
@ -473,9 +479,9 @@ TABLE
|
|||||||
),
|
),
|
||||||
'default',
|
'default',
|
||||||
<<<TABLE
|
<<<TABLE
|
||||||
+--+--+--+--+--+--+--+--+--+
|
+---+--+--+---+--+---+--+---+--+
|
||||||
| 1 | 2 | 3 | 4 |
|
| 1 | 2 | 3 | 4 |
|
||||||
+--+--+--+--+--+--+--+--+--+
|
+---+--+--+---+--+---+--+---+--+
|
||||||
|
|
||||||
TABLE
|
TABLE
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user