8000 feature #50691 [Console] Aligned multiline text in vertical table (ja… · symfony/symfony@d48b929 · GitHub
[go: up one dir, main page]

Skip to content

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

Commit d48b929

Browse files
committed
feature #50691 [Console] Aligned multiline text in vertical table (jaytaph)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Console] Aligned multiline text in vertical table | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #50632 | License | MIT | Doc PR | symfony/symfony-docs#... When using a vertical table helper in the console, any multi-line (\n) text starts on a new line underneath the header. This fixes so the extra lines are aligned with the first line in the table. Commits ------- 67fb325 [Console] Aligned multiline text in vertical table
2 parents 3394330 + 67fb325 commit d48b929

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/Symfony/Component/Console/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `SignalMap` to map signal value to its name
8+
* Multi-line text in vertical tables is aligned properly
89

910
6.3
1011
---

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,26 @@ public function render()
364364
$maxRows = max(\count($headers), \count($row));
365365
for ($i = 0; $i < $maxRows; ++$i) {
366366
$cell = (string) ($row[$i] ?? '');
367-
if ($headers && !$containsColspan) {
368-
$rows[] = [sprintf(
369-
'<comment>%s</>: %s',
370-
str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
371-
$cell
372-
)];
373-
} elseif ('' !== $cell) {
374-
$rows[] = [$cell];
367+
368+
$parts = explode("\n", $cell);
369+
foreach ($parts as $idx => $part) {
370+
if ($headers && !$containsColspan) {
371+
if (0 === $idx) {
372+
$rows[] = [sprintf(
373+
'<comment>%s</>: %s',
374+
str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
375+
$part
376+
)];
377+
} else {
378+
$rows[] = [sprintf(
379+
'%s %s',
380+
str_pad('', $maxHeaderLength, ' ', \STR_PAD_LEFT),
381+
$part
382+
)];
383+
}
384+
} elseif ('' !== $cell) {
385+
$rows[] = [$part];
386+
}
375387
}
376388
}
377389
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ public static function provideRenderVerticalTests(): \Traversable
17201720
|-------------------------|
17211721
| ISBN: 9971-5-0210-0 |
17221722
| Title: A Tale |
1723-
| of Two Cities |
1723+
| of Two Cities |
17241724
| Author: Charles Dickens |
17251725
| Price: 139.25 |
17261726
+-------------------------+

0 commit comments

Comments
 (0)
0