8000 [console][table] adjust width of colspanned cell. · symfony/symfony@aa349df · GitHub
[go: up one dir, main page]

Skip to content

Commit aa349df

Browse files
committed
[console][table] adjust width of colspanned cell.
1 parent fb92d7a commit aa349df

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,19 @@ private function getColumnWidth($column)
521521
continue;
522522
}
523523

524+
// split the TableCell centent in order to extending width of other columns
525+
foreach ($row as $i => $cell) {
526+
if ($cell instanceof TableCell) {
527+
$textLength = strlen($cell);
528+
if ($textLength > 0) {
529+
$contentColumns = str_split($cell, ceil($textLength/$cell->getColspan()));
530+
foreach ($contentColumns as $position => $content) {
531+
$row[$i + $position] = $content;
532+
}
533+
}
534+
}
535+
}
536+
524537
$lengths[] = $this->getCellWidth($row, $column);
525538
}
526539

@@ -550,10 +563,6 @@ private function getCellWidth(array $row, $column)
550563
if (isset($row[$column])) {
551564
$cell = $row[$column];
552565
$cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
553-
if ($cell instanceof TableCell && $cell->getColspan() > 1) {
554-
// we assume that cell value will be across more than one column.
555-
$cellWidth = $cellWidth / $cell->getColspan();
556-
}
557566

558567
return $cellWidth;
559568
}

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

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,27 @@ public function testRenderProvider()
269269
'9971-5-0210-0',
270270
new TableCell("A Tale of \nTwo Cities", array('colspan' => 2)),
271271
),
272+
new TableSeparator(),
273+
array(
274+
new TableCell("Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil!", array('colspan' => 3)),
275+
),
272276
),
273277
'default',
274278
<<<TABLE
275-
+----------------+---------------+-----------------+
276-
| ISBN | Title | Author |
277-
+----------------+---------------+-----------------+
278-
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
279-
+----------------+---------------+-----------------+
280-
| Divine Comedy(Dante Alighieri) |
281-
+----------------+---------------+-----------------+
282-
| Arduino: A Quick-Start Guide | Mark Schmidt |
283-
+----------------+---------------+-----------------+
284-
| 9971-5-0210-0 | A Tale of |
285-
| | Two Cities |
286-
+----------------+---------------+-----------------+
279+
+-------------------------------+-------------------------------+-----------------------------+
280+
| ISBN | Title | Author |
281+
+-------------------------------+-------------------------------+-----------------------------+
282+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
283+
+-------------------------------+-------------------------------+-----------------------------+
284+
| Divine Comedy(Dante Alighieri) |
285+
+-------------------------------+-------------------------------+-----------------------------+
286+
| Arduino: A Quick-Start Guide | Mark Schmidt |
287+
+-------------------------------+-------------------------------+-----------------------------+
288+
| 9971-5-0210-0 | A Tale of |
289+
| | Two Cities |
290+
+-------------------------------+-------------------------------+-----------------------------+
291+
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
292+
+-------------------------------+-------------------------------+-----------------------------+
287293
288294
TABLE
289295
),
@@ -336,16 +342,16 @@ public function testRenderProvider()
336342
),
337343
'default',
338344
<<<TABLE
339-
+------------------+--------+-----------------+
340-
| ISBN | Title | Author |
341-
+------------------+--------+-----------------+
342-
| 9971-5-0210-0 | Dante Alighieri |
343-
| | Charles Dickens |
344-
+------------------+--------+-----------------+
345-
| Dante Alighieri | 9971-5-0210-0 |
346-
| J. R. R. Tolkien | |
347-
| J. R. R | |
348-
+------------------+--------+-----------------+
345+
+------------------+---------+-----------------+
346+
| ISBN | Title | Author |
347+
+------------------+---------+-----------------+
348+
| 9971-5-0210-0 | Dante Alighieri |
349+
| | Charles Dickens |
350+
+------------------+---------+-----------------+
351+
| Dante Alighieri | 9971-5-0210-0 |
352+
| J. R. R. Tolkien | |
353+
| J. R. R | |
354+
+------------------+---------+-----------------+
349355
350356
TABLE
351357
),
@@ -473,9 +479,9 @@ public function testRenderProvider()
473479
),
474480
'default',
475481
<<<TABLE
476-
+--+--+--+--+--+--+--+--+--+
477-
| 1 | 2 | 3 | 4 |
478-
+--+--+--+--+--+--+--+--+--+
482+
+---+--+--+---+--+---+--+---+--+
483+
| 1 | 2 | 3 | 4 |
484+
+---+--+--+---+--+---+--+---+--+
479485
480486
TABLE
481487
),

0 commit comments

Comments
 (0)
0