diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/console/Style | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/console/Style')
| -rw-r--r-- | vendor/symfony/console/Style/OutputStyle.php | 109 | ||||
| -rw-r--r-- | vendor/symfony/console/Style/StyleInterface.php | 110 | ||||
| -rw-r--r-- | vendor/symfony/console/Style/SymfonyStyle.php | 455 |
3 files changed, 674 insertions, 0 deletions
diff --git a/vendor/symfony/console/Style/OutputStyle.php b/vendor/symfony/console/Style/OutputStyle.php new file mode 100644 index 0000000..9f62ea3 --- /dev/null +++ b/vendor/symfony/console/Style/OutputStyle.php | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Console\Style; | ||
| 13 | |||
| 14 | use Symfony\Component\Console\Formatter\OutputFormatterInterface; | ||
| 15 | use Symfony\Component\Console\Helper\ProgressBar; | ||
| 16 | use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
| 17 | use Symfony\Component\Console\Output\OutputInterface; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Decorates output to add console style guide helpers. | ||
| 21 | * | ||
| 22 | * @author Kevin Bond <kevinbond@gmail.com> | ||
| 23 | */ | ||
| 24 | abstract class OutputStyle implements OutputInterface, StyleInterface | ||
| 25 | { | ||
| 26 | public function __construct( | ||
| 27 | private OutputInterface $output, | ||
| 28 | ) { | ||
| 29 | } | ||
| 30 | |||
| 31 | public function newLine(int $count = 1): void | ||
| 32 | { | ||
| 33 | $this->output->write(str_repeat(\PHP_EOL, $count)); | ||
| 34 | } | ||
| 35 | |||
| 36 | public function createProgressBar(int $max = 0): ProgressBar | ||
| 37 | { | ||
| 38 | return new ProgressBar($this->output, $max); | ||
| 39 | } | ||
| 40 | |||
| 41 | public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL): void | ||
| 42 | { | ||
| 43 | $this->output->write($messages, $newline, $type); | ||
| 44 | } | ||
| 45 | |||
| 46 | public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL): void | ||
| 47 | { | ||
| 48 | $this->output->writeln($messages, $type); | ||
| 49 | } | ||
| 50 | |||
| 51 | public function setVerbosity(int $level): void | ||
| 52 | { | ||
| 53 | $this->output->setVerbosity($level); | ||
| 54 | } | ||
| 55 | |||
| 56 | public function getVerbosity(): int | ||
| 57 | { | ||
| 58 | return $this->output->getVerbosity(); | ||
| 59 | } | ||
| 60 | |||
| 61 | public function setDecorated(bool $decorated): void | ||
| 62 | { | ||
| 63 | $this->output->setDecorated($decorated); | ||
| 64 | } | ||
| 65 | |||
| 66 | public function isDecorated(): bool | ||
| 67 | { | ||
| 68 | return $this->output->isDecorated(); | ||
| 69 | } | ||
| 70 | |||
| 71 | public function setFormatter(OutputFormatterInterface $formatter): void | ||
| 72 | { | ||
| 73 | $this->output->setFormatter($formatter); | ||
| 74 | } | ||
| 75 | |||
| 76 | public function getFormatter(): OutputFormatterInterface | ||
| 77 | { | ||
| 78 | return $this->output->getFormatter(); | ||
| 79 | } | ||
| 80 | |||
| 81 | public function isQuiet(): bool | ||
| 82 | { | ||
| 83 | return $this->output->isQuiet(); | ||
| 84 | } | ||
| 85 | |||
| 86 | public function isVerbose(): bool | ||
| 87 | { | ||
| 88 | return $this->output->isVerbose(); | ||
| 89 | } | ||
| 90 | |||
| 91 | public function isVeryVerbose(): bool | ||
| 92 | { | ||
| 93 | return $this->output->isVeryVerbose(); | ||
| 94 | } | ||
| 95 | |||
| 96 | public function isDebug(): bool | ||
| 97 | { | ||
| 98 | return $this->output->isDebug(); | ||
| 99 | } | ||
| 100 | |||
| 101 | protected function getErrorOutput(): OutputInterface | ||
| 102 | { | ||
| 103 | if (!$this->output instanceof ConsoleOutputInterface) { | ||
| 104 | return $this->output; | ||
| 105 | } | ||
| 106 | |||
| 107 | return $this->output->getErrorOutput(); | ||
| 108 | } | ||
| 109 | } | ||
diff --git a/vendor/symfony/console/Style/StyleInterface.php b/vendor/symfony/console/Style/StyleInterface.php new file mode 100644 index 0000000..fcc5bc7 --- /dev/null +++ b/vendor/symfony/console/Style/StyleInterface.php | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Console\Style; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Output style helpers. | ||
| 16 | * | ||
| 17 | * @author Kevin Bond <kevinbond@gmail.com> | ||
| 18 | */ | ||
| 19 | interface StyleInterface | ||
| 20 | { | ||
| 21 | /** | ||
| 22 | * Formats a command title. | ||
| 23 | */ | ||
| 24 | public function title(string $message): void; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Formats a section title. | ||
| 28 | */ | ||
| 29 | public function section(string $message): void; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Formats a list. | ||
| 33 | */ | ||
| 34 | public function listing(array $elements): void; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Formats informational text. | ||
| 38 | */ | ||
| 39 | public function text(string|array $message): void; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Formats a success result bar. | ||
| 43 | */ | ||
| 44 | public function success(string|array $message): void; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Formats an error result bar. | ||
| 48 | */ | ||
| 49 | public function error(string|array $message): void; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Formats an warning result bar. | ||
| 53 | */ | ||
| 54 | public function warning(string|array $message): void; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Formats a note admonition. | ||
| 58 | */ | ||
| 59 | public function note(string|array $message): void; | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Formats a caution admonition. | ||
| 63 | */ | ||
| 64 | public function caution(string|array $message): void; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Formats a table. | ||
| 68 | */ | ||
| 69 | public function table(array $headers, array $rows): void; | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Asks a question. | ||
| 73 | */ | ||
| 74 | public function ask(string $question, ?string $default = null, ?callable $validator = null): mixed; | ||
| 75 | |||
| 76 | /** | ||
| 77 | * Asks a question with the user input hidden. | ||
| 78 | */ | ||
| 79 | public function askHidden(string $question, ?callable $validator = null): mixed; | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Asks for confirmation. | ||
| 83 | */ | ||
| 84 | public function confirm(string $question, bool $default = true): bool; | ||
| 85 | |||
| 86 | /** | ||
| 87 | * Asks a choice question. | ||
| 88 | */ | ||
| 89 | public function choice(string $question, array $choices, mixed $default = null): mixed; | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Add newline(s). | ||
| 93 | */ | ||
| 94 | public function newLine(int $count = 1): void; | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Starts the progress output. | ||
| 98 | */ | ||
| 99 | public function progressStart(int $max = 0): void; | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Advances the progress output X steps. | ||
| 103 | */ | ||
| 104 | public function progressAdvance(int $step = 1): void; | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Finishes the progress output. | ||
| 108 | */ | ||
| 109 | public function progressFinish(): void; | ||
| 110 | } | ||
diff --git a/vendor/symfony/console/Style/SymfonyStyle.php b/vendor/symfony/console/Style/SymfonyStyle.php new file mode 100644 index 0000000..19ad892 --- /dev/null +++ b/vendor/symfony/console/Style/SymfonyStyle.php | |||
| @@ -0,0 +1,455 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /* | ||
| 4 | * This file is part of the Symfony package. | ||
| 5 | * | ||
| 6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
| 7 | * | ||
| 8 | * For the full copyright and license information, please view the LICENSE | ||
| 9 | * file that was distributed with this source code. | ||
| 10 | */ | ||
| 11 | |||
| 12 | namespace Symfony\Component\Console\Style; | ||
| 13 | |||
| 14 | use Symfony\Component\Console\Exception\InvalidArgumentException; | ||
| 15 | use Symfony\Component\Console\Exception\RuntimeException; | ||
| 16 | use Symfony\Component\Console\Formatter\OutputFormatter; | ||
| 17 | use Symfony\Component\Console\Helper\Helper; | ||
| 18 | use Symfony\Component\Console\Helper\OutputWrapper; | ||
| 19 | use Symfony\Component\Console\Helper\ProgressBar; | ||
| 20 | use Symfony\Component\Console\Helper\SymfonyQuestionHelper; | ||
| 21 | use Symfony\Component\Console\Helper\Table; | ||
| 22 | use Symfony\Component\Console\Helper\TableCell; | ||
| 23 | use Symfony\Component\Console\Helper\TableSeparator; | ||
| 24 | use Symfony\Component\Console\Input\InputInterface; | ||
| 25 | use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
| 26 | use Symfony\Component\Console\Output\ConsoleSectionOutput; | ||
| 27 | use Symfony\Component\Console\Output\OutputInterface; | ||
| 28 | use Symfony\Component\Console\Output\TrimmedBufferOutput; | ||
| 29 | use Symfony\Component\Console\Question\ChoiceQuestion; | ||
| 30 | use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
| 31 | use Symfony\Component\Console\Question\Question; | ||
| 32 | use Symfony\Component\Console\Terminal; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Output decorator helpers for the Symfony Style Guide. | ||
| 36 | * | ||
| 37 | * @author Kevin Bond <kevinbond@gmail.com> | ||
| 38 | */ | ||
| 39 | class SymfonyStyle extends OutputStyle | ||
| 40 | { | ||
| 41 | public const MAX_LINE_LENGTH = 120; | ||
| 42 | |||
| 43 | private SymfonyQuestionHelper $questionHelper; | ||
| 44 | private ProgressBar $progressBar; | ||
| 45 | private int $lineLength; | ||
| 46 | private TrimmedBufferOutput $bufferedOutput; | ||
| 47 | |||
| 48 | public function __construct( | ||
| 49 | private InputInterface $input, | ||
| 50 | private OutputInterface $output, | ||
| 51 | ) { | ||
| 52 | $this->bufferedOutput = new TrimmedBufferOutput(\DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $output->getVerbosity(), false, clone $output->getFormatter()); | ||
| 53 | // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not. | ||
| 54 | $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH; | ||
| 55 | $this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH); | ||
| 56 | |||
| 57 | parent::__construct($output); | ||
| 58 | } | ||
| 59 | |||
| 60 | /** | ||
| 61 | * Formats a message as a block of text. | ||
| 62 | */ | ||
| 63 | public function block(string|array $messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true): void | ||
| 64 | { | ||
| 65 | $messages = \is_array($messages) ? array_values($messages) : [$messages]; | ||
| 66 | |||
| 67 | $this->autoPrependBlock(); | ||
| 68 | $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape)); | ||
| 69 | $this->newLine(); | ||
| 70 | } | ||
| 71 | |||
| 72 | public function title(string $message): void | ||
| 73 | { | ||
| 74 | $this->autoPrependBlock(); | ||
| 75 | $this->writeln([ | ||
| 76 | sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), | ||
| 77 | sprintf('<comment>%s</>', str_repeat('=', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), | ||
| 78 | ]); | ||
| 79 | $this->newLine(); | ||
| 80 | } | ||
| 81 | |||
| 82 | public function section(string $message): void | ||
| 83 | { | ||
| 84 | $this->autoPrependBlock(); | ||
| 85 | $this->writeln([ | ||
| 86 | sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), | ||
| 87 | sprintf('<comment>%s</>', str_repeat('-', Helper::width(Helper::removeDecoration($this->getFormatter(), $message)))), | ||
| 88 | ]); | ||
| 89 | $this->newLine(); | ||
| 90 | } | ||
| 91 | |||
| 92 | public function listing(array $elements): void | ||
| 93 | { | ||
| 94 | $this->autoPrependText(); | ||
| 95 | $elements = array_map(fn ($element) => sprintf(' * %s', $element), $elements); | ||
| 96 | |||
| 97 | $this->writeln($elements); | ||
| 98 | $this->newLine(); | ||
| 99 | } | ||
| 100 | |||
| 101 | public function text(string|array $message): void | ||
| 102 | { | ||
| 103 | $this->autoPrependText(); | ||
| 104 | |||
| 105 | $messages = \is_array($message) ? array_values($message) : [$message]; | ||
| 106 | foreach ($messages as $message) { | ||
| 107 | $this->writeln(sprintf(' %s', $message)); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * Formats a command comment. | ||
| 113 | */ | ||
| 114 | public function comment(string|array $message): void | ||
| 115 | { | ||
| 116 | $this->block($message, null, null, '<fg=default;bg=default> // </>', false, false); | ||
| 117 | } | ||
| 118 | |||
| 119 | public function success(string|array $message): void | ||
| 120 | { | ||
| 121 | $this->block($message, 'OK', 'fg=black;bg=green', ' ', true); | ||
| 122 | } | ||
| 123 | |||
| 124 | public function error(string|array $message): void | ||
| 125 | { | ||
| 126 | $this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true); | ||
| 127 | } | ||
| 128 | |||
| 129 | public function warning(string|array $message): void | ||
| 130 | { | ||
| 131 | $this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true); | ||
| 132 | } | ||
| 133 | |||
| 134 | public function note(string|array $message): void | ||
| 135 | { | ||
| 136 | $this->block($message, 'NOTE', 'fg=yellow', ' ! '); | ||
| 137 | } | ||
| 138 | |||
| 139 | /** | ||
| 140 | * Formats an info message. | ||
| 141 | */ | ||
| 142 | public function info(string|array $message): void | ||
| 143 | { | ||
| 144 | $this->block($message, 'INFO', 'fg=green', ' ', true); | ||
| 145 | } | ||
| 146 | |||
| 147 | public function caution(string|array $message): void | ||
| 148 | { | ||
| 149 | $this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true); | ||
| 150 | } | ||
| 151 | |||
| 152 | public function table(array $headers, array $rows): void | ||
| 153 | { | ||
| 154 | $this->createTable() | ||
| 155 | ->setHeaders($headers) | ||
| 156 | ->setRows($rows) | ||
| 157 | ->render() | ||
| 158 | ; | ||
| 159 | |||
| 160 | $this->newLine(); | ||
| 161 | } | ||
| 162 | |||
| 163 | /** | ||
| 164 | * Formats a horizontal table. | ||
| 165 | */ | ||
| 166 | public function horizontalTable(array $headers, array $rows): void | ||
| 167 | { | ||
| 168 | $this->createTable() | ||
| 169 | ->setHorizontal(true) | ||
| 170 | ->setHeaders($headers) | ||
| 171 | ->setRows($rows) | ||
| 172 | ->render() | ||
| 173 | ; | ||
| 174 | |||
| 175 | $this->newLine(); | ||
| 176 | } | ||
| 177 | |||
| 178 | /** | ||
| 179 | * Formats a list of key/value horizontally. | ||
| 180 | * | ||
| 181 | * Each row can be one of: | ||
| 182 | * * 'A title' | ||
| 183 | * * ['key' => 'value'] | ||
| 184 | * * new TableSeparator() | ||
| 185 | */ | ||
| 186 | public function definitionList(string|array|TableSeparator ...$list): void | ||
| 187 | { | ||
| 188 | $headers = []; | ||
| 189 | $row = []; | ||
| 190 | foreach ($list as $value) { | ||
| 191 | if ($value instanceof TableSeparator) { | ||
| 192 | $headers[] = $value; | ||
| 193 | $row[] = $value; | ||
| 194 | continue; | ||
| 195 | } | ||
| 196 | if (\is_string($value)) { | ||
| 197 | $headers[] = new TableCell($value, ['colspan' => 2]); | ||
| 198 | $row[] = null; | ||
| 199 | continue; | ||
| 200 | } | ||
| 201 | if (!\is_array($value)) { | ||
| 202 | throw new InvalidArgumentException('Value should be an array, string, or an instance of TableSeparator.'); | ||
| 203 | } | ||
| 204 | $headers[] = key($value); | ||
| 205 | $row[] = current($value); | ||
| 206 | } | ||
| 207 | |||
| 208 | $this->horizontalTable($headers, [$row]); | ||
| 209 | } | ||
| 210 | |||
| 211 | public function ask(string $question, ?string $default = null, ?callable $validator = null): mixed | ||
| 212 | { | ||
| 213 | $question = new Question($question, $default); | ||
| 214 | $question->setValidator($validator); | ||
| 215 | |||
| 216 | return $this->askQuestion($question); | ||
| 217 | } | ||
| 218 | |||
| 219 | public function askHidden(string $question, ?callable $validator = null): mixed | ||
| 220 | { | ||
| 221 | $question = new Question($question); | ||
| 222 | |||
| 223 | $question->setHidden(true); | ||
| 224 | $question->setValidator($validator); | ||
| 225 | |||
| 226 | return $this->askQuestion($question); | ||
| 227 | } | ||
| 228 | |||
| 229 | public function confirm(string $question, bool $default = true): bool | ||
| 230 | { | ||
| 231 | return $this->askQuestion(new ConfirmationQuestion($question, $default)); | ||
| 232 | } | ||
| 233 | |||
| 234 | public function choice(string $question, array $choices, mixed $default = null, bool $multiSelect = false): mixed | ||
| 235 | { | ||
| 236 | if (null !== $default) { | ||
| 237 | $values = array_flip($choices); | ||
| 238 | $default = $values[$default] ?? $default; | ||
| 239 | } | ||
| 240 | |||
| 241 | $questionChoice = new ChoiceQuestion($question, $choices, $default); | ||
| 242 | $questionChoice->setMultiselect($multiSelect); | ||
| 243 | |||
| 244 | return $this->askQuestion($questionChoice); | ||
| 245 | } | ||
| 246 | |||
| 247 | public function progressStart(int $max = 0): void | ||
| 248 | { | ||
| 249 | $this->progressBar = $this->createProgressBar($max); | ||
| 250 | $this->progressBar->start(); | ||
| 251 | } | ||
| 252 | |||
| 253 | public function progressAdvance(int $step = 1): void | ||
| 254 | { | ||
| 255 | $this->getProgressBar()->advance($step); | ||
| 256 | } | ||
| 257 | |||
| 258 | public function progressFinish(): void | ||
| 259 | { | ||
| 260 | $this->getProgressBar()->finish(); | ||
| 261 | $this->newLine(2); | ||
| 262 | unset($this->progressBar); | ||
| 263 | } | ||
| 264 | |||
| 265 | public function createProgressBar(int $max = 0): ProgressBar | ||
| 266 | { | ||
| 267 | $progressBar = parent::createProgressBar($max); | ||
| 268 | |||
| 269 | if ('\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv('TERM_PROGRAM')) { | ||
| 270 | $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591 | ||
| 271 | $progressBar->setProgressCharacter(''); | ||
| 272 | $progressBar->setBarCharacter('▓'); // dark shade character \u2593 | ||
| 273 | } | ||
| 274 | |||
| 275 | return $progressBar; | ||
| 276 | } | ||
| 277 | |||
| 278 | /** | ||
| 279 | * @see ProgressBar::iterate() | ||
| 280 | * | ||
| 281 | * @template TKey | ||
| 282 | * @template TValue | ||
| 283 | * | ||
| 284 | * @param iterable<TKey, TValue> $iterable | ||
| 285 | * @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable | ||
| 286 | * | ||
| 287 | * @return iterable<TKey, TValue> | ||
| 288 | */ | ||
| 289 | public function progressIterate(iterable $iterable, ?int $max = null): iterable | ||
| 290 | { | ||
| 291 | yield from $this->createProgressBar()->iterate($iterable, $max); | ||
| 292 | |||
| 293 | $this->newLine(2); | ||
| 294 | } | ||
| 295 | |||
| 296 | public function askQuestion(Question $question): mixed | ||
| 297 | { | ||
| 298 | if ($this->input->isInteractive()) { | ||
| 299 | $this->autoPrependBlock(); | ||
| 300 | } | ||
| 301 | |||
| 302 | $this->questionHelper ??= new SymfonyQuestionHelper(); | ||
| 303 | |||
| 304 | $answer = $this->questionHelper->ask($this->input, $this, $question); | ||
| 305 | |||
| 306 | if ($this->input->isInteractive()) { | ||
| 307 | if ($this->output instanceof ConsoleSectionOutput) { | ||
| 308 | // add the new line of the `return` to submit the input to ConsoleSectionOutput, because ConsoleSectionOutput is holding all it's lines. | ||
| 309 | // this is relevant when a `ConsoleSectionOutput::clear` is called. | ||
| 310 | $this->output->addNewLineOfInputSubmit(); | ||
| 311 | } | ||
| 312 | $this->newLine(); | ||
| 313 | $this->bufferedOutput->write("\n"); | ||
| 314 | } | ||
| 315 | |||
| 316 | return $answer; | ||
| 317 | } | ||
| 318 | |||
| 319 | public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL): void | ||
| 320 | { | ||
| 321 | if (!is_iterable($messages)) { | ||
| 322 | $messages = [$messages]; | ||
| 323 | } | ||
| 324 | |||
| 325 | foreach ($messages as $message) { | ||
| 326 | parent::writeln($message, $type); | ||
| 327 | $this->writeBuffer($message, true, $type); | ||
| 328 | } | ||
| 329 | } | ||
| 330 | |||
| 331 | public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL): void | ||
| 332 | { | ||
| 333 | if (!is_iterable($messages)) { | ||
| 334 | $messages = [$messages]; | ||
| 335 | } | ||
| 336 | |||
| 337 | foreach ($messages as $message) { | ||
| 338 | parent::write($message, $newline, $type); | ||
| 339 | $this->writeBuffer($message, $newline, $type); | ||
| 340 | } | ||
| 341 | } | ||
| 342 | |||
| 343 | public function newLine(int $count = 1): void | ||
| 344 | { | ||
| 345 | parent::newLine($count); | ||
| 346 | $this->bufferedOutput->write(str_repeat("\n", $count)); | ||
| 347 | } | ||
| 348 | |||
| 349 | /** | ||
| 350 | * Returns a new instance which makes use of stderr if available. | ||
| 351 | */ | ||
| 352 | public function getErrorStyle(): self | ||
| 353 | { | ||
| 354 | return new self($this->input, $this->getErrorOutput()); | ||
| 355 | } | ||
| 356 | |||
| 357 | public function createTable(): Table | ||
| 358 | { | ||
| 359 | $output = $this->output instanceof ConsoleOutputInterface ? $this->output->section() : $this->output; | ||
| 360 | $style = clone Table::getStyleDefinition('symfony-style-guide'); | ||
| 361 | $style->setCellHeaderFormat('<info>%s</info>'); | ||
| 362 | |||
| 363 | return (new Table($output))->setStyle($style); | ||
| 364 | } | ||
| 365 | |||
| 366 | private function getProgressBar(): ProgressBar | ||
| 367 | { | ||
| 368 | return $this->progressBar | ||
| 369 | ?? throw new RuntimeException('The ProgressBar is not started.'); | ||
| 370 | } | ||
| 371 | |||
| 372 | private function autoPrependBlock(): void | ||
| 373 | { | ||
| 374 | $chars = substr(str_replace(\PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2); | ||
| 375 | |||
| 376 | if (!isset($chars[0])) { | ||
| 377 | $this->newLine(); // empty history, so we should start with a new line. | ||
| 378 | |||
| 379 | return; | ||
| 380 | } | ||
| 381 | // Prepend new line for each non LF chars (This means no blank line was output before) | ||
| 382 | $this->newLine(2 - substr_count($chars, "\n")); | ||
| 383 | } | ||
| 384 | |||
| 385 | private function autoPrependText(): void | ||
| 386 | { | ||
| 387 | $fetched = $this->bufferedOutput->fetch(); | ||
| 388 | // Prepend new line if last char isn't EOL: | ||
| 389 | if ($fetched && !str_ends_with($fetched, "\n")) { | ||
| 390 | $this->newLine(); | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | private function writeBuffer(string $message, bool $newLine, int $type): void | ||
| 395 | { | ||
| 396 | // We need to know if the last chars are PHP_EOL | ||
| 397 | $this->bufferedOutput->write($message, $newLine, $type); | ||
| 398 | } | ||
| 399 | |||
| 400 | private function createBlock(iterable $messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false): array | ||
| 401 | { | ||
| 402 | $indentLength = 0; | ||
| 403 | $prefixLength = Helper::width(Helper::removeDecoration($this->getFormatter(), $prefix)); | ||
| 404 | $lines = []; | ||
| 405 | |||
| 406 | if (null !== $type) { | ||
| 407 | $type = sprintf('[%s] ', $type); | ||
| 408 | $indentLength = Helper::width($type); | ||
| 409 | $lineIndentation = str_repeat(' ', $indentLength); | ||
| 410 | } | ||
| 411 | |||
| 412 | // wrap and add newlines for each element | ||
| 413 | $outputWrapper = new OutputWrapper(); | ||
| 414 | foreach ($messages as $key => $message) { | ||
| 415 | if ($escape) { | ||
| 416 | $message = OutputFormatter::escape($message); | ||
| 417 | } | ||
| 418 | |||
| 419 | $lines = array_merge( | ||
| 420 | $lines, | ||
| 421 | explode(\PHP_EOL, $outputWrapper->wrap( | ||
| 422 | $message, | ||
| 423 | $this->lineLength - $prefixLength - $indentLength, | ||
| 424 | \PHP_EOL | ||
| 425 | )) | ||
| 426 | ); | ||
| 427 | |||
| 428 | if (\count($messages) > 1 && $key < \count($messages) - 1) { | ||
| 429 | $lines[] = ''; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | $firstLineIndex = 0; | ||
| 434 | if ($padding && $this->isDecorated()) { | ||
| 435 | $firstLineIndex = 1; | ||
| 436 | array_unshift($lines, ''); | ||
| 437 | $lines[] = ''; | ||
| 438 | } | ||
| 439 | |||
| 440 | foreach ($lines as $i => &$line) { | ||
| 441 | if (null !== $type) { | ||
| 442 | $line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line; | ||
| 443 | } | ||
| 444 | |||
| 445 | $line = $prefix.$line; | ||
| 446 | $line .= str_repeat(' ', max($this->lineLength - Helper::width(Helper::removeDecoration($this->getFormatter(), $line)), 0)); | ||
| 447 | |||
| 448 | if ($style) { | ||
| 449 | $line = sprintf('<%s>%s</>', $style, $line); | ||
| 450 | } | ||
| 451 | } | ||
| 452 | |||
| 453 | return $lines; | ||
| 454 | } | ||
| 455 | } | ||
