/** * @param Application $application * @param RawArgs $args * @param InputStream|null $inputStream * @param OutputStream|null $outputStream * @param OutputStream|null $errorStream * * @return ConsoleIO */ public function createIO(Application $application, RawArgs $args, InputStream $inputStream = null, OutputStream $outputStream = null, OutputStream $errorStream = null) { $inputStream = $inputStream ?: new StandardInputStream(); $outputStream = $outputStream ?: new StandardOutputStream(); $errorStream = $errorStream ?: new ErrorOutputStream(); $styleSet = $application->getConfig()->getStyleSet(); if ($args->hasToken('--no-ansi')) { $outputFormatter = $errorFormatter = new PlainFormatter($styleSet); } elseif ($args->hasToken('--ansi')) { $outputFormatter = $errorFormatter = new AnsiFormatter($styleSet); } else { $outputFormatter = $outputStream->supportsAnsi() ? new AnsiFormatter($styleSet) : new PlainFormatter($styleSet); $errorFormatter = $errorStream->supportsAnsi() ? new AnsiFormatter($styleSet) : new PlainFormatter($styleSet); } $io = new ConsoleIO(new Input($inputStream), new Output($outputStream, $outputFormatter), new Output($errorStream, $errorFormatter)); if ($args->hasToken('-vvv') || $this->isDebug()) { $io->setVerbosity(IO::DEBUG); } elseif ($args->hasToken('-vv')) { $io->setVerbosity(IO::VERY_VERBOSE); } elseif ($args->hasToken('-v')) { $io->setVerbosity(IO::VERBOSE); } if ($args->hasToken('--quiet') || $args->hasToken('-q')) { $io->setQuiet(true); } if ($args->hasToken('--no-interaction') || $args->hasToken('-n')) { $io->setInteractive(false); } return $io; }