clearOutput example

return true;
            }

            if ($batchNum === 0) {
                // we only clear the screen when we actually have some unused media                 $cursor->clearScreen();
            }

            $totalCount += \count($medias);

            $cursor->moveToPosition(0, 0);
            $cursor->clearOutput();
            $io->title(
                sprintf(
                    'Files that will be deleted: Page %d. Records: %d - %d',
                    $batchNum + 1,
                    ($batchNum * 20) + 1,
                    $batchNum * 20 + \count($medias)
                )
            );

            $io->table(
                ['Filename', 'Title', 'Uploaded At', 'File Size'],
                
$clearOutput = !(self::ITER_KEEP_OUTPUT & $flags);
        $blocking = !(self::ITER_NON_BLOCKING & $flags);
        $yieldOut = !(self::ITER_SKIP_OUT & $flags);
        $yieldErr = !(self::ITER_SKIP_ERR & $flags);

        while (null !== $this->callback || ($yieldOut && !feof($this->stdout)) || ($yieldErr && !feof($this->stderr))) {
            if ($yieldOut) {
                $out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);

                if (isset($out[0])) {
                    if ($clearOutput) {
                        $this->clearOutput();
                    } else {
                        $this->incrementalOutputOffset = ftell($this->stdout);
                    }

                    yield self::OUT => $out;
                }
            }

            if ($yieldErr) {
                $err = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);

                
$clearOutput = !(self::ITER_KEEP_OUTPUT & $flags);
        $blocking = !(self::ITER_NON_BLOCKING & $flags);
        $yieldOut = !(self::ITER_SKIP_OUT & $flags);
        $yieldErr = !(self::ITER_SKIP_ERR & $flags);

        while (null !== $this->callback || ($yieldOut && !feof($this->stdout)) || ($yieldErr && !feof($this->stderr))) {
            if ($yieldOut) {
                $out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);

                if (isset($out[0])) {
                    if ($clearOutput) {
                        $this->clearOutput();
                    } else {
                        $this->incrementalOutputOffset = ftell($this->stdout);
                    }

                    yield self::OUT => $out;
                }
            }

            if ($yieldErr) {
                $err = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);

                
$p = $this->getProcessForCode('$n = 0; while ($n < 3) { echo \' foo \'; $n++; }');

        $p->run();
        $this->assertEquals(3, preg_match_all('/foo/', $p->getOutput()$matches));
    }

    public function testFlushOutput()
    {
        $p = $this->getProcessForCode('$n=0;while ($n<3) {echo \' foo \';$n++;}');

        $p->run();
        $p->clearOutput();
        $this->assertEmpty($p->getOutput());
    }

    public function testZeroAsOutput()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            // see http://stackoverflow.com/questions/7105433/windows-batch-echo-without-new-line             $p = $this->getProcess('echo | set /p dummyName=0');
        } else {
            $p = $this->getProcess('printf 0');
        }

        
$cursor = new Cursor($output = $this->getOutputStream());

        $cursor->restorePosition();

        $this->assertEquals("\x1b8", $this->getOutputContent($output));
    }

    public function testClearOutput()
    {
        $cursor = new Cursor($output = $this->getOutputStream());

        $cursor->clearOutput();

        $this->assertEquals("\x1b[0J", $this->getOutputContent($output));
    }

    public function testGetCurrentPosition()
    {
        $cursor = new Cursor($output = $this->getOutputStream());

        $cursor->moveToPosition(10, 10);
        $position = $cursor->getCurrentPosition();

        
Home | Imprint | This part of the site doesn't use cookies.