Sha256: d16996a56648f3a9c95133e051a5f8c43394cae9002eaa4aef3ea4cdb49807fe

Contents?: true

Size: 1.77 KB

Versions: 36

Compression:

Stored size: 1.77 KB

Contents

<?php

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\IO;

use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Helper\HelperSet;

/**
 * @author Jordi Boggiano <j.boggiano@seld.be>
 */
class BufferIO extends ConsoleIO
{
    /**
     * @param string                        $input
     * @param int                           $verbosity
     * @param OutputFormatterInterface|null $formatter
     */
    public function __construct($input = '', $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null)
    {
        $input = new StringInput($input);
        $input->setInteractive(false);

        $output = new StreamOutput(fopen('php://memory', 'rw'), $verbosity, $formatter ? $formatter->isDecorated() : false, $formatter);

        parent::__construct($input, $output, new HelperSet(array()));
    }

    public function getOutput()
    {
        fseek($this->output->getStream(), 0);

        $output = stream_get_contents($this->output->getStream());

        $output = preg_replace_callback("{(?<=^|\n|\x08)(.+?)(\x08+)}", function ($matches) {
            $pre = strip_tags($matches[1]);

            if (strlen($pre) === strlen($matches[2])) {
                return '';
            }

            // TODO reverse parse the string, skipping span tags and \033\[([0-9;]+)m(.*?)\033\[0m style blobs
            return rtrim($matches[1])."\n";
        }, $output);

        return $output;
    }
}

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
dependabot-composer-0.111.50 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.111.25 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.111.17 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.111.15 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.110.13 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.108.11 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.108.8 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.107.47 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.107.39 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.107.36 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.107.28 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.107.14 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.106.12 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.106.11 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.106.5 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.100.2 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.98.36 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.98.19 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.98.13 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php
dependabot-composer-0.98.11 helpers/vendor/composer/composer/src/Composer/IO/BufferIO.php