10000 [Console] Aligned multiline text in vertical table · symfony/symfony@67fb325 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67fb325

Browse files
jaytaphfabpot
authored andcommitted
[Console] Aligned multiline text in vertical table
1 parent 3394330 commit 67fb325

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