Skip to content

Fixed the line length of the new Symfony Styles #14136

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

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 13 additions & 2 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Console\Style;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Helper\ProgressBar;
Expand All @@ -34,6 +35,7 @@ class SymfonyStyle extends OutputStyle
private $input;
private $questionHelper;
private $progressBar;
private $lineLength;

/**
* @param InputInterface $input
Expand All @@ -42,6 +44,7 @@ class SymfonyStyle extends OutputStyle
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->lineLength = min($this->getTerminalWidth(), self::MAX_LINE_LENGTH);

parent::__construct($output);
}
Expand All @@ -68,7 +71,7 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa
// wrap and add newlines for each element
foreach ($messages as $key => $message) {
$message = OutputFormatter::escape($message);
$lines = array_merge($lines, explode("\n", wordwrap($message, self::MAX_LINE_LENGTH - Helper::strlen($prefix))));
$lines = array_merge($lines, explode("\n", wordwrap($message, $this->lineLength - Helper::strlen($prefix))));

if (count($messages) > 1 && $key < count($message)) {
$lines[] = '';
Expand All @@ -82,7 +85,7 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa

foreach ($lines as &$line) {
$line = sprintf('%s%s', $prefix, $line);
$line .= str_repeat(' ', self::MAX_LINE_LENGTH - Helper::strlen($line));
$line .= str_repeat(' ', $this->lineLength - Helper::strlen($line));

if ($style) {
$line = sprintf('<%s>%s</>', $style, $line);
Expand Down Expand Up @@ -307,4 +310,12 @@ private function getProgressBar()

return $this->progressBar;
}

private function getTerminalWidth()
{
$application = new Application();
list ($width, $height) = $application->getTerminalDimensions();

return $width;
}
}