comparison vendor/symfony/console/Style/SymfonyStyle.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
44 { 44 {
45 $this->input = $input; 45 $this->input = $input;
46 $this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter()); 46 $this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter());
47 // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not. 47 // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not.
48 $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH; 48 $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH;
49 $this->lineLength = min($width - (int) (DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH); 49 $this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
50 50
51 parent::__construct($output); 51 parent::__construct($output);
52 } 52 }
53 53
54 /** 54 /**
61 * @param bool $padding Whether to add vertical padding 61 * @param bool $padding Whether to add vertical padding
62 * @param bool $escape Whether to escape the message 62 * @param bool $escape Whether to escape the message
63 */ 63 */
64 public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true) 64 public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true)
65 { 65 {
66 $messages = is_array($messages) ? array_values($messages) : array($messages); 66 $messages = \is_array($messages) ? array_values($messages) : [$messages];
67 67
68 $this->autoPrependBlock(); 68 $this->autoPrependBlock();
69 $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape)); 69 $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape));
70 $this->newLine(); 70 $this->newLine();
71 } 71 }
74 * {@inheritdoc} 74 * {@inheritdoc}
75 */ 75 */
76 public function title($message) 76 public function title($message)
77 { 77 {
78 $this->autoPrependBlock(); 78 $this->autoPrependBlock();
79 $this->writeln(array( 79 $this->writeln([
80 sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), 80 sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
81 sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))), 81 sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
82 )); 82 ]);
83 $this->newLine(); 83 $this->newLine();
84 } 84 }
85 85
86 /** 86 /**
87 * {@inheritdoc} 87 * {@inheritdoc}
88 */ 88 */
89 public function section($message) 89 public function section($message)
90 { 90 {
91 $this->autoPrependBlock(); 91 $this->autoPrependBlock();
92 $this->writeln(array( 92 $this->writeln([
93 sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)), 93 sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
94 sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))), 94 sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
95 )); 95 ]);
96 $this->newLine(); 96 $this->newLine();
97 } 97 }
98 98
99 /** 99 /**
100 * {@inheritdoc} 100 * {@inheritdoc}
115 */ 115 */
116 public function text($message) 116 public function text($message)
117 { 117 {
118 $this->autoPrependText(); 118 $this->autoPrependText();
119 119
120 $messages = is_array($message) ? array_values($message) : array($message); 120 $messages = \is_array($message) ? array_values($message) : [$message];
121 foreach ($messages as $message) { 121 foreach ($messages as $message) {
122 $this->writeln(sprintf(' %s', $message)); 122 $this->writeln(sprintf(' %s', $message));
123 } 123 }
124 } 124 }
125 125
267 */ 267 */
268 public function createProgressBar($max = 0) 268 public function createProgressBar($max = 0)
269 { 269 {
270 $progressBar = parent::createProgressBar($max); 270 $progressBar = parent::createProgressBar($max);
271 271
272 if ('\\' !== DIRECTORY_SEPARATOR) { 272 if ('\\' !== \DIRECTORY_SEPARATOR || 'Hyper' === getenv('TERM_PROGRAM')) {
273 $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591 273 $progressBar->setEmptyBarCharacter('░'); // light shade character \u2591
274 $progressBar->setProgressCharacter(''); 274 $progressBar->setProgressCharacter('');
275 $progressBar->setBarCharacter('▓'); // dark shade character \u2593 275 $progressBar->setBarCharacter('▓'); // dark shade character \u2593
276 } 276 }
277 277
374 { 374 {
375 // We need to know if the two last chars are PHP_EOL 375 // We need to know if the two last chars are PHP_EOL
376 // Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer 376 // Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer
377 return array_map(function ($value) { 377 return array_map(function ($value) {
378 return substr($value, -4); 378 return substr($value, -4);
379 }, array_merge(array($this->bufferedOutput->fetch()), (array) $messages)); 379 }, array_merge([$this->bufferedOutput->fetch()], (array) $messages));
380 } 380 }
381 381
382 private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false) 382 private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false)
383 { 383 {
384 $indentLength = 0; 384 $indentLength = 0;
385 $prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix); 385 $prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
386 $lines = array(); 386 $lines = [];
387 387
388 if (null !== $type) { 388 if (null !== $type) {
389 $type = sprintf('[%s] ', $type); 389 $type = sprintf('[%s] ', $type);
390 $indentLength = strlen($type); 390 $indentLength = \strlen($type);
391 $lineIndentation = str_repeat(' ', $indentLength); 391 $lineIndentation = str_repeat(' ', $indentLength);
392 } 392 }
393 393
394 // wrap and add newlines for each element 394 // wrap and add newlines for each element
395 foreach ($messages as $key => $message) { 395 foreach ($messages as $key => $message) {
397 $message = OutputFormatter::escape($message); 397 $message = OutputFormatter::escape($message);
398 } 398 }
399 399
400 $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - $prefixLength - $indentLength, PHP_EOL, true))); 400 $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - $prefixLength - $indentLength, PHP_EOL, true)));
401 401
402 if (count($messages) > 1 && $key < count($messages) - 1) { 402 if (\count($messages) > 1 && $key < \count($messages) - 1) {
403 $lines[] = ''; 403 $lines[] = '';
404 } 404 }
405 } 405 }
406 406
407 $firstLineIndex = 0; 407 $firstLineIndex = 0;