X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Frobo%2Fsrc%2FCommon%2FIO.php;fp=vendor%2Fconsolidation%2Frobo%2Fsrc%2FCommon%2FIO.php;h=d6c77bff8dd3f0ccf50c6cd7a40ec979f89d3c62;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/consolidation/robo/src/Common/IO.php b/vendor/consolidation/robo/src/Common/IO.php new file mode 100644 index 000000000..d6c77bff8 --- /dev/null +++ b/vendor/consolidation/robo/src/Common/IO.php @@ -0,0 +1,171 @@ +io) { + $this->io = new SymfonyStyle($this->input(), $this->output()); + } + return $this->io; + } + + /** + * @param string $nonDecorated + * @param string $decorated + * + * @return string + */ + protected function decorationCharacter($nonDecorated, $decorated) + { + if (!$this->output()->isDecorated() || (strncasecmp(PHP_OS, 'WIN', 3) == 0)) { + return $nonDecorated; + } + return $decorated; + } + + /** + * @param string $text + */ + protected function say($text) + { + $char = $this->decorationCharacter('>', '➜'); + $this->writeln("$char $text"); + } + + /** + * @param string $text + * @param int $length + * @param string $color + */ + protected function yell($text, $length = 40, $color = 'green') + { + $char = $this->decorationCharacter(' ', '➜'); + $format = "$char %s"; + $this->formattedOutput($text, $length, $format); + } + + /** + * @param string $text + * @param int $length + * @param string $format + */ + protected function formattedOutput($text, $length, $format) + { + $lines = explode("\n", trim($text, "\n")); + $maxLineLength = array_reduce(array_map('strlen', $lines), 'max'); + $length = max($length, $maxLineLength); + $len = $length + 2; + $space = str_repeat(' ', $len); + $this->writeln(sprintf($format, $space)); + foreach ($lines as $line) { + $line = str_pad($line, $length, ' ', STR_PAD_BOTH); + $this->writeln(sprintf($format, " $line ")); + } + $this->writeln(sprintf($format, $space)); + } + + /** + * @param string $question + * @param bool $hideAnswer + * + * @return string + */ + protected function ask($question, $hideAnswer = false) + { + if ($hideAnswer) { + return $this->askHidden($question); + } + return $this->doAsk(new Question($this->formatQuestion($question))); + } + + /** + * @param string $question + * + * @return string + */ + protected function askHidden($question) + { + $question = new Question($this->formatQuestion($question)); + $question->setHidden(true); + return $this->doAsk($question); + } + + /** + * @param string $question + * @param string $default + * + * @return string + */ + protected function askDefault($question, $default) + { + return $this->doAsk(new Question($this->formatQuestion("$question [$default]"), $default)); + } + + /** + * @param string $question + * + * @return string + */ + protected function confirm($question) + { + return $this->doAsk(new ConfirmationQuestion($this->formatQuestion($question . ' (y/n)'), false)); + } + + /** + * @param \Symfony\Component\Console\Question\Question $question + * + * @return string + */ + protected function doAsk(Question $question) + { + return $this->getDialog()->ask($this->input(), $this->output(), $question); + } + + /** + * @param string $message + * + * @return string + */ + protected function formatQuestion($message) + { + return "? $message "; + } + + /** + * @return \Symfony\Component\Console\Helper\QuestionHelper + */ + protected function getDialog() + { + return new QuestionHelper(); + } + + /** + * @param $text + */ + protected function writeln($text) + { + $this->output()->writeln($text); + } +}