8000 bug #21438 [Console] Fix TableCell issues with decoration (ogizanagi) · symfony/symfony@f7ba71d · GitHub
[go: up one dir, main page]

Skip to content

Commit f7ba71d

Browse files
bug #21438 [Console] Fix TableCell issues with decoration (ogizanagi)
This PR was merged into the 2.7 branch. Discussion ---------- [Console] Fix TableCell issues with decoration | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes (failure unrelated) | Fixed tickets | #21434 | License | MIT | Doc PR | N/A Commits ------- 50373f3 [Console] Fix TableCell issues with decoration
2 parents 536e073 + 50373f3 commit f7ba71d

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ private function getColumnWidth($column)
518518

519519
foreach ($row as $i => $cell) {
520520
if ($cell instanceof TableCell) {
521-
$textLength = strlen($cell);
521+
$textLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
522522
if ($textLength > 0) {
523523
$contentColumns = str_split($cell, ceil($textLength / $cell->getColspan()));
524524
foreach ($contentColumns as $position => $content) {

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

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ protected function tearDown()
3535
/**
3636
* @dataProvider testRenderProvider
3737
*/
38-
public function testRender($headers, $rows, $style, $expected)
38+
public function testRender($headers, $rows, $style, $expected, $decorated = false)
3939
{
40-
$table = new Table($output = $this->getOutputStream());
40+
$table = new Table($output = $this->getOutputStream($decorated));
4141
$table
4242
->setHeaders($headers)
4343
->setRows($rows)
@@ -51,9 +51,9 @@ public function testRender($headers, $rows, $style, $expected)
5151
/**
5252
* @dataProvider testRenderProvider
5353
*/
54-
public function testRenderAddRows($headers, $rows, $style, $expected)
54+
public function testRenderAddRows($headers, $rows, $style, $expected, $decorated = false)
5555
{
56-
$table = new Table($output = $this->getOutputStream());
56+
$table = new Table($output = $this->getOutputStream($decorated));
5757
$table
5858
->setHeaders($headers)
5959
->addRows($rows)
@@ -67,9 +67,9 @@ public function testRenderAddRows($headers, $rows, $style, $expected)
6767
/**
6868
* @dataProvider testRenderProvider
6969
*/
70-
public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected)
70+
public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false)
7171
{
72-
$table = new Table($output = $this->getOutputStream());
72+
$table = new Table($output = $this->getOutputStream($decorated));
7373
$table
7474
->setHeaders($headers)
7575
->setStyle($style)
@@ -485,6 +485,35 @@ public function testRenderProvider()
485485

486486
TABLE
487487
),
488+
'Coslpan and table cells with comment style' => array(
489+
array(
490+
new TableCell('<comment>Long Title</comment>', array('colspan' => 3)),
491+
),
492+
array(
493+
array(
494+
new TableCell('9971-5-0210-0', array('colspan' => 3)),
495+
),
496+
new TableSeparator(),
497+
array(
498+
'Dante Alighieri',
499+
'J. R. R. Tolkien',
500+
'J. R. R',
501+
),
502+
),
503+
'default',
504+
<<<TABLE
505+
+-----------------+------------------+---------+
506+
|\033[32m \033[39m\033[33mLong Title\033[39m\033[32m \033[39m|
507+
+-----------------+------------------+---------+
508+
| 9971-5-0210-0 |
509+
+-----------------+------------------+---------+
510+
| Dante Alighieri | J. R. R. Tolkien | J. R. R |
511+
+-----------------+------------------+---------+
512+
513+
TABLE
514+
,
515+
true,
516+
),
488517
);
489518
}
490519

@@ -596,9 +625,9 @@ public function testGetStyleDefinition()
596625
Table::getStyleDefinition('absent');
597626
}
598627

599-
protected function getOutputStream()
628+
protected function getOutputStream($decorated = false)
600629
{
601-
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, false);
630+
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
602631
}
603632

604633
protected function getOutputContent(StreamOutput $output)

0 commit comments

Comments
 (0)
0