Skip to content

Commit 27228d3

Browse files
committed
Fixed table
1 parent 168ed9c commit 27228d3

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public function getHelperSet()
4242
/**
4343
* Returns the length of a string, using mb_strwidth if it is available.
4444
*
45+
* @deprecated since 5.2
4546
* @return int The length of the string
4647
*/
4748
public static function strlen(?string $string)
4849
{
49-
trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::strwidth() or Helper::strlength() instead.', __METHOD__);
50+
trigger_deprecation('symfony/console', '5.2', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::strwidth() or Helper::strlength() instead.', __METHOD__);
5051

5152
return self::strwidth($string);
5253
}
@@ -155,7 +156,17 @@ public static function formatMemory(int $memory)
155156
return sprintf('%d B', $memory);
156157
}
157158

159+
/**
160+
* @deprecated since 5.2
161+
*/
158162
public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string)
163+
{
164+
trigger_deprecation('symfony/console', '5.2', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::strwidthWithoutDecoration() or Helper::strlengthWithoutDecoration() instead.', __METHOD__);
165+
166+
return self::strwidthWithoutDecoration($formatter, $string);
167+
}
168+
169+
public static function strwidthWithoutDecoration(OutputFormatterInterface $formatter, ?string $string)
159170
{
160171
$string = self::removeDecoration($formatter, $string);
161172

@@ -166,6 +177,13 @@ public static function strlenWithoutDecoration(OutputFormatterInterface $formatt
166177
return self::strwidth($string);
167178
}
168179

180+
public static function strlengthWithoutDecoration(OutputFormatterInterface $formatter, ?string $string)
181+
{
182+
$string = self::removeDecoration($formatter, $string);
183+
184+
return self::strlength($string);
185+
}
186+
169187
public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string)
170188
{
171189
$isDecorated = $formatter->isDecorated();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ private function overwrite(string $message): void
465465
$messageLines = explode("\n", $message);
466466
$lineCount = \count($messageLines);
467467
foreach ($messageLines as $messageLine) {
468-
$messageLineLength = Helper::strlenWithoutDecoration($this->output->getFormatter(), $messageLine);
468+
$messageLineLength = Helper::strwidthWithoutDecoration($this->output->getFormatter(), $messageLine);
469469
if ($messageLineLength > $this->terminal->getWidth()) {
470470
$lineCount += floor($messageLineLength / $this->terminal->getWidth());
471471
}
@@ -513,7 +513,7 @@ private static function initPlaceholderFormatters(): array
513513
$completeBars = $bar->getBarOffset();
514514
$display = str_repeat($bar->getBarCharacter(), $completeBars);
515515
if ($completeBars < $bar->getBarWidth()) {
516-
$emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
516+
$emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlengthWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
517517
$display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
518518
}
519519

@@ -590,7 +590,7 @@ private function buildLine(): string
590590

591591
// gets string length for each sub line with multiline format
592592
$linesLength = array_map(function ($subLine) {
593-
return Helper::strlenWithoutDecoration($this->output->getFormatter(), rtrim($subLine, "\r"));
593+
return Helper::strwidthWithoutDecoration($this->output->getFormatter(), rtrim($subLine, "\r"));
594594
}, explode("\n", $line));
595595

596596
$linesWidth = max($linesLength);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ private function renderRowSeparator(int $type = self::SEPARATOR_MID, string $tit
434434
}
435435

436436
if (null !== $title) {
437-
$titleLength = Helper::strlenWithoutDecoration($formatter = $this->output->getFormatter(), $formattedTitle = sprintf($titleFormat, $title));
437+
$titleLength = Helper::strwidthWithoutDecoration($formatter = $this->output->getFormatter(), $formattedTitle = sprintf($titleFormat, $title));
438438
$markupLength = Helper::strwidth($markup);
439439
if ($titleLength > $limit = $markupLength - 4) {
440440
$titleLength = $limit;
441-
$formatLength = Helper::strlenWithoutDecoration($formatter, sprintf($titleFormat, ''));
441+
$formatLength = Helper::strwidthWithoutDecoration($formatter, sprintf($titleFormat, ''));
442442
$formattedTitle = sprintf($titleFormat, Helper::substr($title, 0, $limit - $formatLength - 3).'...');
443443
}
444444

@@ -511,7 +511,7 @@ private function renderCell(array $row, int $column, string $cellFormat): string
511511
return sprintf($style->getBorderFormat(), str_repeat($style->getBorderChars()[2], $width));
512512
}
513513

514-
$width += Helper::strwidth($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
514+
$width += Helper::strlength($cell) - Helper::strlengthWithoutDecoration($this->output->getFormatter(), $cell);
515515
$content = sprintf($style->getCellRowContentFormat(), $cell);
516516

517517
$padType = $style->getPadType();
@@ -569,7 +569,7 @@ private function buildTableRows(array $rows): TableRows
569569
foreach ($rows[$rowKey] as $column => $cell) {
570570
$colspan = $cell instanceof TableCell ? $cell->getColspan() : 1;
571571

572-
if (isset($this->columnMaxWidths[$column]) && Helper::strlenWithoutDecoration($formatter, $cell) > $this->columnMaxWidths[$column]) {
572+
if (isset($this->columnMaxWidths[$column]) && Helper::strwidthWithoutDecoration($formatter, $cell) > $this->columnMaxWidths[$column]) {
573573
$cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column] * $colspan);
574574
}
575575
if (!strstr($cell, "\n")) {
@@ -783,7 +783,7 @@ private function getCellWidth(array $row, int $column): int
783783

784784
if (isset($row[$column])) {
785785
$cell = $row[$column];
786-
$cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
786+
$cellWidth = Helper::strwidthWithoutDecoration($this->output->getFormatter(), $cell);
787787
}
788788

789789
$columnWidth = $this->columnWidths[$column] ?? 0;

src/Symfony/Component/Console/Output/ConsoleSectionOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFr
138138

139139
private function getDisplayLength(string $text): string
140140
{
141-
return Helper::strlenWithoutDecoration($this->getFormatter(), str_replace("\t", ' ', $text));
141+
return Helper::strwidthWithoutDecoration($this->getFormatter(), str_replace("\t", ' ', $text));
142142
}
143143
}

src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function title(string $message)
7676
$this->autoPrependBlock();
7777
$this->writeln([
7878
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
79-
sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
79+
sprintf('<comment>%s</>', str_repeat('=', Helper::strwidthWithoutDecoration($this->getFormatter(), $message))),
8080
]);
8181
$this->newLine();
8282
}
@@ -89,7 +89,7 @@ public function section(string $message)
8989
$this->autoPrependBlock();
9090
$this->writeln([
9191
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
92-
sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
92+
sprintf('<comment>%s</>', str_repeat('-', Helper::strwidthWithoutDecoration($this->getFormatter(), $message))),
9393
]);
9494
$this->newLine();
9595
}
@@ -461,7 +461,7 @@ private function writeBuffer(string $message, bool $newLine, int $type): void
461461
private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array
462462
{
463463
$indentLength = 0;
464-
$prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
464+
$prefixLength = Helper::strwidthWithoutDecoration($this->getFormatter(), $prefix);
465465
$lines = [];
466466

467467
if (null !== $type) {
@@ -476,7 +476,7 @@ private function createBlock(iterable $messages, string $type = null, string $st
476476
$message = OutputFormatter::escape($message);
477477
}
478478

479-
$decorationLength = Helper::strwidth($message) - Helper::strlenWithoutDecoration($this->getFormatter(), $message);
479+
$decorationLength = Helper::strwidth($message) - Helper::strwidthWithoutDecoration($this->getFormatter(), $message);
480480
$messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength);
481481
$messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true));
482482
foreach ($messageLines as $messageLine) {
@@ -501,7 +501,7 @@ private function createBlock(iterable $messages, string $type = null, string $st
501501
}
502502

503503
$line = $prefix.$line;
504-
$line .= str_repeat(' ', max($this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line), 0));
504+
$line .= str_repeat(' ', max($this->lineLength - Helper::strwidthWithoutDecoration($this->getFormatter(), $line), 0));
505505

506506
if ($style) {
507507
$line = sprintf('<%s>%s</>', $style, $line);

0 commit comments

Comments
 (0)