Skip to content

Commit f9c0b6c

Browse files
authored
Merge pull request #34 from SimonFrings/eventloop
Simplify examples by updating to new default loop
2 parents af4441c + dde740d commit f9c0b6c

File tree

6 files changed

+11
-28
lines changed

6 files changed

+11
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ It wraps a given `ReadableStreamInterface` and exposes its plain data through
3636
the same interface.
3737

3838
```php
39-
$stdin = new ReadableResourceStream(STDIN, $loop);
39+
$stdin = new React\Stream\ReadableResourceStream(STDIN);
4040

4141
$stream = new ControlCodeParser($stdin);
4242

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
},
1919
"require": {
2020
"php": ">=5.3",
21-
"react/stream": "^1.0 || ^0.7"
21+
"react/stream": "^1.2"
2222
},
2323
"require-dev": {
2424
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8",
25-
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3"
25+
"react/event-loop": "^1.2"
2626
}
2727
}

examples/random-colors.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,22 @@
1111
// with random colors:
1212
// $ phpunit --color=always | php random-colors.php
1313

14-
use React\EventLoop\Factory;
1514
use Clue\React\Term\ControlCodeParser;
1615
use React\Stream\ReadableResourceStream;
1716
use React\Stream\WritableResourceStream;
1817

1918
require __DIR__ . '/../vendor/autoload.php';
2019

21-
$loop = Factory::create();
22-
2320
if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
2421
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
2522
shell_exec('stty -icanon -echo');
2623
}
2724

2825
// process control codes from STDIN
29-
$stdin = new ReadableResourceStream(STDIN, $loop);
26+
$stdin = new ReadableResourceStream(STDIN);
3027
$parser = new ControlCodeParser($stdin);
3128

32-
$stdout = new WritableResourceStream(STDOUT, $loop);
29+
$stdout = new WritableResourceStream(STDOUT);
3330

3431
// pass all c0 codes through to output
3532
$parser->on('c0', array($stdout, 'write'));
@@ -55,5 +52,3 @@
5552

5653
// start with random color
5754
$stdin->emit('data', array("\033[m"));
58-
59-
$loop->run();

examples/remove-codes.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,23 @@
88
// codes like this:
99
// $ phpunit --color=always | php remove-codes.php
1010

11-
use React\EventLoop\Factory;
1211
use Clue\React\Term\ControlCodeParser;
1312
use React\Stream\ReadableResourceStream;
1413
use React\Stream\WritableResourceStream;
1514

1615
require __DIR__ . '/../vendor/autoload.php';
1716

18-
$loop = Factory::create();
19-
2017
if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
2118
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
2219
shell_exec('stty -icanon -echo');
2320
}
2421

2522
// process control codes from STDIN
26-
$stdin = new ReadableResourceStream(STDIN, $loop);
23+
$stdin = new ReadableResourceStream(STDIN);
2724
$parser = new ControlCodeParser($stdin);
2825

2926
// pipe data from STDIN to STDOUT without any codes
30-
$stdout = new WritableResourceStream(STDOUT, $loop);
27+
$stdout = new WritableResourceStream(STDOUT);
3128
$parser->pipe($stdout);
3229

3330
// only forward \r, \n and \t
@@ -36,5 +33,3 @@
3633
$stdout->write($code);
3734
}
3835
});
39-
40-
$loop->run();

examples/stdin-codes.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
// codes like this:
1010
// $ phpunit --color=always | php stdin-codes.php
1111

12-
use React\EventLoop\Factory;
1312
use Clue\React\Term\ControlCodeParser;
1413
use React\Stream\ReadableResourceStream;
1514

1615
require __DIR__ . '/../vendor/autoload.php';
1716

18-
$loop = Factory::create();
19-
2017
if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
2118
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
2219
shell_exec('stty -icanon -echo');
2320
}
2421

2522
// process control codes from STDIN
26-
$stdin = new ReadableResourceStream(STDIN, $loop);
23+
$stdin = new ReadableResourceStream(STDIN);
2724
$parser = new ControlCodeParser($stdin);
2825

2926
$decoder = function ($code) {
@@ -42,5 +39,3 @@
4239
$parser->on('data', function ($bytes) {
4340
echo 'Data: ' . $bytes . PHP_EOL;
4441
});
45-
46-
$loop->run();

tests/FunctionalControlCodeParserTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@
33
namespace Clue\Tests\React\Term;
44

55
use Clue\React\Term\ControlCodeParser;
6-
use React\EventLoop\Factory;
6+
use React\EventLoop\Loop;
77
use React\Stream\ReadableResourceStream;
88

99
class FunctionalControlCodeParserTest extends TestCase
1010
{
1111
public function testPipingReadme()
1212
{
13-
$loop = Factory::create();
14-
15-
$input = new ReadableResourceStream(fopen(__DIR__ . '/../README.md', 'r+'), $loop);
13+
$input = new ReadableResourceStream(fopen(__DIR__ . '/../README.md', 'r+'));
1614
$parser = new ControlCodeParser($input);
1715

1816
$buffer = '';
1917
$parser->on('data', function ($chunk) use (&$buffer) {
2018
$buffer .= $chunk;
2119
});
2220

23-
$loop->run();
21+
Loop::run();
2422

2523
$readme = str_replace(
2624
"\n",

0 commit comments

Comments
 (0)