Dep: update
주로 PHAN
This commit is contained in:
+32
-18
@@ -21,8 +21,8 @@ use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\TrimmedBufferOutput;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
@@ -35,7 +35,7 @@ use Symfony\Component\Console\Terminal;
|
||||
*/
|
||||
class SymfonyStyle extends OutputStyle
|
||||
{
|
||||
const MAX_LINE_LENGTH = 120;
|
||||
public const MAX_LINE_LENGTH = 120;
|
||||
|
||||
private $input;
|
||||
private $questionHelper;
|
||||
@@ -46,7 +46,7 @@ class SymfonyStyle extends OutputStyle
|
||||
public function __construct(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter());
|
||||
$this->bufferedOutput = new TrimmedBufferOutput(\DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $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.
|
||||
$width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH;
|
||||
$this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
|
||||
@@ -59,7 +59,7 @@ class SymfonyStyle extends OutputStyle
|
||||
*
|
||||
* @param string|array $messages The message to write in the block
|
||||
*/
|
||||
public function block($messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true)
|
||||
public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true)
|
||||
{
|
||||
$messages = \is_array($messages) ? array_values($messages) : [$messages];
|
||||
|
||||
@@ -76,7 +76,7 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->autoPrependBlock();
|
||||
$this->writeln([
|
||||
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
|
||||
sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
|
||||
sprintf('<comment>%s</>', str_repeat('=', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))),
|
||||
]);
|
||||
$this->newLine();
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->autoPrependBlock();
|
||||
$this->writeln([
|
||||
sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
|
||||
sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
|
||||
sprintf('<comment>%s</>', str_repeat('-', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))),
|
||||
]);
|
||||
$this->newLine();
|
||||
}
|
||||
@@ -163,6 +163,16 @@ class SymfonyStyle extends OutputStyle
|
||||
$this->block($message, 'NOTE', 'fg=yellow', ' ! ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an info message.
|
||||
*
|
||||
* @param string|array $message
|
||||
*/
|
||||
public function info($message)
|
||||
{
|
||||
$this->block($message, 'INFO', 'fg=green', ' ', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -254,7 +264,7 @@ class SymfonyStyle extends OutputStyle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ask(string $question, ?string $default = null, $validator = null)
|
||||
public function ask(string $question, string $default = null, callable $validator = null)
|
||||
{
|
||||
$question = new Question($question, $default);
|
||||
$question->setValidator($validator);
|
||||
@@ -265,7 +275,7 @@ class SymfonyStyle extends OutputStyle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function askHidden(string $question, $validator = null)
|
||||
public function askHidden(string $question, callable $validator = null)
|
||||
{
|
||||
$question = new Question($question);
|
||||
|
||||
@@ -278,7 +288,7 @@ class SymfonyStyle extends OutputStyle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function confirm($question, $default = true)
|
||||
public function confirm(string $question, bool $default = true)
|
||||
{
|
||||
return $this->askQuestion(new ConfirmationQuestion($question, $default));
|
||||
}
|
||||
@@ -290,7 +300,7 @@ class SymfonyStyle extends OutputStyle
|
||||
{
|
||||
if (null !== $default) {
|
||||
$values = array_flip($choices);
|
||||
$default = isset($values[$default]) ? $values[$default] : $default;
|
||||
$default = $values[$default] ?? $default;
|
||||
}
|
||||
|
||||
return $this->askQuestion(new ChoiceQuestion($question, $choices, $default));
|
||||
@@ -422,7 +432,7 @@ class SymfonyStyle extends OutputStyle
|
||||
|
||||
private function autoPrependBlock(): void
|
||||
{
|
||||
$chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
|
||||
$chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
|
||||
|
||||
if (!isset($chars[0])) {
|
||||
$this->newLine(); //empty history, so we should start with a new line.
|
||||
@@ -437,22 +447,21 @@ class SymfonyStyle extends OutputStyle
|
||||
{
|
||||
$fetched = $this->bufferedOutput->fetch();
|
||||
//Prepend new line if last char isn't EOL:
|
||||
if ("\n" !== substr($fetched, -1)) {
|
||||
if (!str_ends_with($fetched, "\n")) {
|
||||
$this->newLine();
|
||||
}
|
||||
}
|
||||
|
||||
private function writeBuffer(string $message, bool $newLine, int $type): void
|
||||
{
|
||||
// We need to know if the two last chars are PHP_EOL
|
||||
// Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer
|
||||
$this->bufferedOutput->write(substr($message, -4), $newLine, $type);
|
||||
// We need to know if the last chars are PHP_EOL
|
||||
$this->bufferedOutput->write($message, $newLine, $type);
|
||||
}
|
||||
|
||||
private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array
|
||||
{
|
||||
$indentLength = 0;
|
||||
$prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
|
||||
$prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix));
|
||||
$lines = [];
|
||||
|
||||
if (null !== $type) {
|
||||
@@ -467,7 +476,12 @@ class SymfonyStyle extends OutputStyle
|
||||
$message = OutputFormatter::escape($message);
|
||||
}
|
||||
|
||||
$lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - $prefixLength - $indentLength, PHP_EOL, true)));
|
||||
$decorationLength = Helper::width($message) - Helper::width(Helper::removeDecoration($this->getFormatter(), $message));
|
||||
$messageLineLength = min($this->lineLength - $prefixLength - $indentLength + $decorationLength, $this->lineLength);
|
||||
$messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true));
|
||||
foreach ($messageLines as $messageLine) {
|
||||
$lines[] = $messageLine;
|
||||
}
|
||||
|
||||
if (\count($messages) > 1 && $key < \count($messages) - 1) {
|
||||
$lines[] = '';
|
||||
@@ -487,7 +501,7 @@ class SymfonyStyle extends OutputStyle
|
||||
}
|
||||
|
||||
$line = $prefix.$line;
|
||||
$line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));
|
||||
$line .= str_repeat(' ', max($this->lineLength - Helper::width(Helper::removeDecoration($this->getFormatter(), $line)), 0));
|
||||
|
||||
if ($style) {
|
||||
$line = sprintf('<%s>%s</>', $style, $line);
|
||||
|
||||
Reference in New Issue
Block a user