Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Table counts wrong column width when using colspan and setColumnMaxWidth() #60044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 6.4
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions 44 src/Symfony/Component/Console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,48 @@ private function buildTableRows(array $rows): TableRows
foreach ($rows[$rowKey] as $column => $cell) {
$colspan = $cell instanceof TableCell ? $cell->getColspan() : 1;

if (isset($this->columnMaxWidths[$column]) && Helper::width(Helper::removeDecoration($formatter, $cell)) > $this->columnMaxWidths[$column]) {
$cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column] * $colspan);
$minWrappedWidth = 0;
$widthApplied = [];
$lengthColumnBorder = $this->getColumnSeparatorWidth() + Helper::width($this->style->getCellRowContentFormat()) - 2;
for ($i = $column; $i < ($column + $colspan); $i++) {
if (isset($this->columnMaxWidths[$i])) {
$minWrappedWidth += $this->columnMaxWidths[$i];
$widthApplied[] = ['type' => 'max', 'column' => $i];
} else if (($this->columnWidths[$i] ?? 0) > 0 && $colspan > 1) {
$minWrappedWidth += $this->columnWidths[$i];
$widthApplied[] = ['type' => 'min', 'column' => $i];
}
}
if (count($widthApplied) === 1) {
if ($colspan > 1) {
$minWrappedWidth = $minWrappedWidth * $colspan; // previous logic
}
} else if (count($widthApplied) > 1) {
$minWrappedWidth += (count($widthApplied) - 1) * $lengthColumnBorder;
}

$cellWidth = Helper::width(Helper::removeDecoration($formatter, $cell));
if ($minWrappedWidth && $cellWidth > $minWrappedWidth) {
$cell = $formatter->formatAndWrap($cell, $minWrappedWidth);
}
// update minimal columnWidths for spanned columns
if ($colspan > 1 && $minWrappedWidth > 0) {
$columnsMinWidthProcessed = [];
$cellWidth = min($cellWidth, $minWrappedWidth);
foreach ($widthApplied as $item) {
if ($item['type'] === 'max' && $cellWidth >= $this->columnMaxWidths[$item['column']]) {
$minWidthColumn = $this->columnMaxWidths[$item['column']];
$this->columnWidths[$item['column']] = $minWidthColumn;
$columnsMinWidthProcessed[] = $item['column'];
$cellWidth -= $minWidthColumn + $lengthColumnBorder;
}
}
for ($i = $column; $i < ($column + $colspan); $i++) {
if (in_array($i, $columnsMinWidthProcessed)) {
continue;
}
$this->columnWidths[$i] = $cellWidth + $lengthColumnBorder;
}
}
if (!str_contains($cell ?? '', "\n")) {
continue;
Expand Down
16 changes: 8 additions & 8 deletions 16 src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1576,17 +1576,17 @@ public function testWithColspanAndMaxWith()
$expected =
<<<TABLE
+-----------------+-----------------+-----------------+
| Lorem ipsum dolor sit amet, consectetur adipi |
| scing elit, sed do eiusmod tempor |
| Lorem ipsum dolor sit amet, consectetur adipiscing |
| elit, sed do eiusmod tempor |
+-----------------+-----------------+-----------------+
| Lorem ipsum dolor sit amet, consectetur |
| adipiscing elit, sed do eiusmod tempor |
| Lorem ipsum dolor sit amet, consectetur adipiscing |
| elit, sed do eiusmod tempor |
+-----------------+-----------------+-----------------+
| Lorem ipsum dolor sit amet, co | hello world |
| nsectetur | |
| Lorem ipsum dolor sit amet, conse | hello world |
| ctetur | |
+-----------------+-----------------+-----------------+
| hello world | Lorem ipsum dolor sit amet, co |
| | nsectetur adipiscing elit |
| hello world | Lorem ipsum dolor sit amet, conse |
| | ctetur adipiscing elit |
+-----------------+-----------------+-----------------+
| hello | world | Lorem ipsum |
| | | dolor sit amet, |
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.