예제 #1
0
<?php

use Clue\React\Stdio\Stdio;
use Clue\React\Stdio\Helper\ProgressBar;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$stdio = new Stdio($loop);
$stdio->writeln('Will print (fake) progress and then exit');
$progress = new ProgressBar($stdio);
$progress->setMaximum(mt_rand(20, 200));
$loop->addPeriodicTimer(0.1, function ($timer) use($stdio, $progress) {
    $progress->advance();
    if ($progress->isComplete()) {
        $stdio->overwrite("Finished processing nothing!" . PHP_EOL);
        $stdio->end();
        $timer->cancel();
    }
});
$loop->run();
예제 #2
0
<?php

use Clue\React\Stdio\Stdio;
use React\EventLoop\LoopInterface;
use Clue\React\Stdio\Helper\Spinner;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$stdio = new Stdio($loop);
$stdio->getReadline()->setPrompt('> ');
$stdio->writeln('Will print a spinner until you enter something');
$stdio->write('  Processing...');
$spinner = new Spinner($loop, $stdio);
$stdio->on('line', function ($line) use($stdio, &$tid, $loop, $spinner) {
    $stdio->overwrite('Processing... DONE');
    $stdio->end();
    $spinner->pause();
});
$loop->run();
예제 #3
0
<?php

use Clue\React\Stdio\Stdio;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$stdio = new Stdio($loop);
$stdio->getReadline()->setPrompt('> ');
$stdio->writeln('Will print periodic messages until you type "quit" or "exit"');
$stdio->on('line', function ($line) use($stdio, $loop, &$timer) {
    $stdio->writeln('you just said: ' . $line . ' (' . strlen($line) . ')');
    if ($line === 'quit' || $line === 'exit') {
        $timer->cancel();
        $stdio->end();
    }
});
// add some periodic noise
$timer = $loop->addPeriodicTimer(2.0, function () use($stdio) {
    $stdio->writeln('hello');
});
$loop->run();
예제 #4
0
 public function testWriteTwoLinesWillClearReadlineWriteOutputAndRestoreReadline()
 {
     $input = $this->getMock('React\\Stream\\ReadableStreamInterface');
     $output = $this->getMock('React\\Stream\\WritableStreamInterface');
     //$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock();
     $readline = new Readline($input, $output);
     $readline->setPrompt('> ');
     $readline->setInput('input');
     $stdio = new Stdio($this->loop, $input, $output, $readline);
     $buffer = '';
     $output->expects($this->any())->method('write')->will($this->returnCallback(function ($data) use(&$buffer) {
         $buffer .= $data;
     }));
     $stdio->writeln('hello');
     $stdio->writeln('world');
     $this->assertEquals("\r" . "hello\n" . "\r" . "> input" . "\r" . "world\n" . "\r" . "> input", $buffer);
 }