Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit 65d5610

Browse files
schlndhondrejmirtes
authored andcommitted
remove manual wrapping for error table
1 parent 2b9e658 commit 65d5610

File tree

1 file changed

+5
-52
lines changed

1 file changed

+5
-52
lines changed

‎src/Command/ErrorsConsoleStyle.php‎

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use OndraM\CiDetector\CiDetector;
66
use Override;
7+
use Symfony\Component\Console\Helper\Helper;
78
use Symfony\Component\Console\Helper\ProgressBar;
89
use Symfony\Component\Console\Helper\TableSeparator;
910
use Symfony\Component\Console\Input\InputInterface;
@@ -14,9 +15,7 @@
1415
use function explode;
1516
use function implode;
1617
use function sprintf;
17-
use function str_starts_with;
1818
use function strlen;
19-
use function wordwrap;
2019
use const DIRECTORY_SEPARATOR;
2120

2221
final class ErrorsConsoleStyle extends SymfonyStyle
@@ -57,19 +56,15 @@ public function table(array $headers, array $rows): void
5756
$terminalWidth = (new Terminal())->getWidth() - 2;
5857
$maxHeaderWidth = strlen($headers[0]);
5958
foreach ($rows as $row) {
60-
$length = strlen($row[0]);
59+
$length = Helper::width(Helper::removeDecoration($this->getFormatter(), $row[0]));
60+
6161
if ($maxHeaderWidth !== 0 && $length <= $maxHeaderWidth) {
6262
continue;
6363
}
6464

6565
$maxHeaderWidth = $length;
6666
}
6767

68-
// manual wrapping could be replaced with $table->setColumnMaxWidth()
69-
// but it's buggy for <href> lines
70-
// https://github.com/symfony/symfony/issues/45520
71-
// https://github.com/symfony/symfony/issues/45521
72-
$headers = $this->wrap($headers, $terminalWidth, $maxHeaderWidth);
7368
foreach ($headers as $i => $header) {
7469
$newHeader = [];
7570
foreach (explode("\n", $header) as $h) {
@@ -79,58 +74,16 @@ public function table(array $headers, array $rows): void
7974
$headers[$i] = implode("\n", $newHeader);
8075
}
8176

82-
foreach ($rows as $i => $row) {
83-
$rows[$i] = $this->wrap($row, $terminalWidth, $maxHeaderWidth);
84-
}
85-
8677
$table = $this->createTable();
78+
// -5 because there are 5 padding spaces: One on each side of the table, one on each side of a cell and one between columns.
79+
$table->setColumnMaxWidth(1, $terminalWidth - $maxHeaderWidth - 5);
8780
array_unshift($rows, $headers, new TableSeparator());
8881
$table->setRows($rows);
8982

9083
$table->render();
9184
$this->newLine();
9285
}
9386

94-
/**
95-
* @param string[] $rows
96-
* @return string[]
97-
*/
98-
private function wrap(array $rows, int $terminalWidth, int $maxHeaderWidth): array
99-
{
100-
foreach ($rows as $i => $column) {
101-
$columnRows = explode("\n", $column);
102-
foreach ($columnRows as $k => $columnRow) {
103-
if (str_starts_with($columnRow, '✏️')) {
104-
continue;
105-
}
106-
$wrapped = wordwrap(
107-
$columnRow,
108-
$terminalWidth - $maxHeaderWidth - 5,
109-
);
110-
if (str_starts_with($columnRow, '💡 ')) {
111-
$wrappedLines = explode("\n", $wrapped);
112-
$newWrappedLines = [];
113-
foreach ($wrappedLines as $l => $line) {
114-
if ($l === 0) {
115-
$newWrappedLines[] = $line;
116-
continue;
117-
}
118-
119-
$newWrappedLines[] = '' . $line;
120-
}
121-
$columnRows[$k] = implode("\n", $newWrappedLines);
122-
} else {
123-
$columnRows[$k] = $wrapped;
124-
}
125-
126-
}
127-
128-
$rows[$i] = implode("\n", $columnRows);
129-
}
130-
131-
return $rows;
132-
}
133-
13487
#[Override]
13588
public function createProgressBar(int $max = 0): ProgressBar
13689
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /