Augmentation vers version 3.3.0
This commit is contained in:
54
vendor/symfony/console/Style/SymfonyStyle.php
vendored
54
vendor/symfony/console/Style/SymfonyStyle.php
vendored
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Console\Style;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\Helper;
|
||||
@@ -24,6 +23,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Terminal;
|
||||
|
||||
/**
|
||||
* Output decorator helpers for the Symfony Style Guide.
|
||||
@@ -45,7 +45,8 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->input = $input;
|
||||
$this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter());
|
||||
// Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not.
|
||||
$this->lineLength = min($this->getTerminalWidth() - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
|
||||
$width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH;
|
||||
$this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
|
||||
|
||||
parent::__construct($output);
|
||||
}
|
||||
@@ -58,13 +59,14 @@ class SymfonyStyle extends OutputStyle
|
||||
* @param string|null $style The style to apply to the whole block
|
||||
* @param string $prefix The prefix for the block
|
||||
* @param bool $padding Whether to add vertical padding
|
||||
* @param bool $escape Whether to escape the message
|
||||
*/
|
||||
public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false)
|
||||
public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true)
|
||||
{
|
||||
$messages = \is_array($messages) ? array_values($messages) : array($messages);
|
||||
$messages = \is_array($messages) ? array_values($messages) : [$messages];
|
||||
|
||||
$this->autoPrependBlock();
|
||||
$this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, true));
|
||||
$this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape));
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
@@ -74,10 +76,10 @@ class SymfonyStyle extends OutputStyle
|
||||
public function title($message)
|
||||
{
|
||||
$this->autoPrependBlock();
|
||||
$this->writeln(array(
|
||||
$this->writeln([
|
||||
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
|
||||
sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
|
||||
));
|
||||
]);
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
@@ -87,10 +89,10 @@ class SymfonyStyle extends OutputStyle
|
||||
public function section($message)
|
||||
{
|
||||
$this->autoPrependBlock();
|
||||
$this->writeln(array(
|
||||
$this->writeln([
|
||||
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
|
||||
sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
|
||||
));
|
||||
]);
|
||||
$this->newLine();
|
||||
}
|
||||
|
||||
@@ -115,7 +117,7 @@ class SymfonyStyle extends OutputStyle
|
||||
{
|
||||
$this->autoPrependText();
|
||||
|
||||
$messages = \is_array($message) ? array_values($message) : array($message);
|
||||
$messages = \is_array($message) ? array_values($message) : [$message];
|
||||
foreach ($messages as $message) {
|
||||
$this->writeln(sprintf(' %s', $message));
|
||||
}
|
||||
@@ -128,11 +130,7 @@ class SymfonyStyle extends OutputStyle
|
||||
*/
|
||||
public function comment($message)
|
||||
{
|
||||
$messages = \is_array($message) ? array_values($message) : array($message);
|
||||
|
||||
$this->autoPrependBlock();
|
||||
$this->writeln($this->createBlock($messages, null, null, '<fg=default;bg=default> // </>'));
|
||||
$this->newLine();
|
||||
$this->block($message, null, null, '<fg=default;bg=default> // </>', false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,6 +328,16 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->bufferedOutput->write(str_repeat("\n", $count));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance which makes use of stderr if available.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function getErrorStyle()
|
||||
{
|
||||
return new self($this->input, $this->getErrorOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ProgressBar
|
||||
*/
|
||||
@@ -342,20 +350,14 @@ class SymfonyStyle extends OutputStyle
|
||||
return $this->progressBar;
|
||||
}
|
||||
|
||||
private function getTerminalWidth()
|
||||
{
|
||||
$application = new Application();
|
||||
$dimensions = $application->getTerminalDimensions();
|
||||
|
||||
return $dimensions[0] ?: self::MAX_LINE_LENGTH;
|
||||
}
|
||||
|
||||
private function autoPrependBlock()
|
||||
{
|
||||
$chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
|
||||
|
||||
if (!isset($chars[0])) {
|
||||
return $this->newLine(); //empty history, so we should start with a new line.
|
||||
$this->newLine(); //empty history, so we should start with a new line.
|
||||
|
||||
return;
|
||||
}
|
||||
//Prepend new line for each non LF chars (This means no blank line was output before)
|
||||
$this->newLine(2 - substr_count($chars, "\n"));
|
||||
@@ -376,14 +378,14 @@ class SymfonyStyle extends OutputStyle
|
||||
// Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer
|
||||
return array_map(function ($value) {
|
||||
return substr($value, -4);
|
||||
}, array_merge(array($this->bufferedOutput->fetch()), (array) $messages));
|
||||
}, array_merge([$this->bufferedOutput->fetch()], (array) $messages));
|
||||
}
|
||||
|
||||
private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false)
|
||||
{
|
||||
$indentLength = 0;
|
||||
$prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
|
||||
$lines = array();
|
||||
$lines = [];
|
||||
|
||||
if (null !== $type) {
|
||||
$type = sprintf('[%s] ', $type);
|
||||
|
||||
Reference in New Issue
Block a user