File tree Expand file tree Collapse file tree 6 files changed +11
-28
lines changed Expand file tree Collapse file tree 6 files changed +11
-28
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ It wraps a given `ReadableStreamInterface` and exposes its plain data through
36
36
the same interface.
37
37
38
38
``` php
39
- $stdin = new ReadableResourceStream(STDIN, $loop );
39
+ $stdin = new React\Stream\ ReadableResourceStream(STDIN);
40
40
41
41
$stream = new ControlCodeParser($stdin);
42
42
Original file line number Diff line number Diff line change 18
18
},
19
19
"require" : {
20
20
"php" : " >=5.3" ,
21
- "react/stream" : " ^1.0 || ^0.7 "
21
+ "react/stream" : " ^1.2 "
22
22
},
23
23
"require-dev" : {
24
24
"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 "
26
26
}
27
27
}
Original file line number Diff line number Diff line change 11
11
// with random colors:
12
12
// $ phpunit --color=always | php random-colors.php
13
13
14
- use React \EventLoop \Factory ;
15
14
use Clue \React \Term \ControlCodeParser ;
16
15
use React \Stream \ReadableResourceStream ;
17
16
use React \Stream \WritableResourceStream ;
18
17
19
18
require __DIR__ . '/../vendor/autoload.php ' ;
20
19
21
- $ loop = Factory::create ();
22
-
23
20
if (function_exists ('posix_isatty ' ) && posix_isatty (STDIN )) {
24
21
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
25
22
shell_exec ('stty -icanon -echo ' );
26
23
}
27
24
28
25
// process control codes from STDIN
29
- $ stdin = new ReadableResourceStream (STDIN , $ loop );
26
+ $ stdin = new ReadableResourceStream (STDIN );
30
27
$ parser = new ControlCodeParser ($ stdin );
31
28
32
- $ stdout = new WritableResourceStream (STDOUT , $ loop );
29
+ $ stdout = new WritableResourceStream (STDOUT );
33
30
34
31
// pass all c0 codes through to output
35
32
$ parser ->on ('c0 ' , array ($ stdout , 'write ' ));
55
52
56
53
// start with random color
57
54
$ stdin ->emit ('data ' , array ("\033[m " ));
58
-
59
- $ loop ->run ();
Original file line number Diff line number Diff line change 8
8
// codes like this:
9
9
// $ phpunit --color=always | php remove-codes.php
10
10
11
- use React \EventLoop \Factory ;
12
11
use Clue \React \Term \ControlCodeParser ;
13
12
use React \Stream \ReadableResourceStream ;
14
13
use React \Stream \WritableResourceStream ;
15
14
16
15
require __DIR__ . '/../vendor/autoload.php ' ;
17
16
18
- $ loop = Factory::create ();
19
-
20
17
if (function_exists ('posix_isatty ' ) && posix_isatty (STDIN )) {
21
18
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
22
19
shell_exec ('stty -icanon -echo ' );
23
20
}
24
21
25
22
// process control codes from STDIN
26
- $ stdin = new ReadableResourceStream (STDIN , $ loop );
23
+ $ stdin = new ReadableResourceStream (STDIN );
27
24
$ parser = new ControlCodeParser ($ stdin );
28
25
29
26
// pipe data from STDIN to STDOUT without any codes
30
- $ stdout = new WritableResourceStream (STDOUT , $ loop );
27
+ $ stdout = new WritableResourceStream (STDOUT );
31
28
$ parser ->pipe ($ stdout );
32
29
33
30
// only forward \r, \n and \t
36
33
$ stdout ->write ($ code );
37
34
}
38
35
});
39
-
40
- $ loop ->run ();
Original file line number Diff line number Diff line change 9
9
// codes like this:
10
10
// $ phpunit --color=always | php stdin-codes.php
11
11
12
- use React \EventLoop \Factory ;
13
12
use Clue \React \Term \ControlCodeParser ;
14
13
use React \Stream \ReadableResourceStream ;
15
14
16
15
require __DIR__ . '/../vendor/autoload.php ' ;
17
16
18
- $ loop = Factory::create ();
19
-
20
17
if (function_exists ('posix_isatty ' ) && posix_isatty (STDIN )) {
21
18
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
22
19
shell_exec ('stty -icanon -echo ' );
23
20
}
24
21
25
22
// process control codes from STDIN
26
- $ stdin = new ReadableResourceStream (STDIN , $ loop );
23
+ $ stdin = new ReadableResourceStream (STDIN );
27
24
$ parser = new ControlCodeParser ($ stdin );
28
25
29
26
$ decoder = function ($ code ) {
42
39
$ parser ->on ('data ' , function ($ bytes ) {
43
40
echo 'Data: ' . $ bytes . PHP_EOL ;
44
41
});
45
-
46
- $ loop ->run ();
Original file line number Diff line number Diff line change 3
3
namespace Clue \Tests \React \Term ;
4
4
5
5
use Clue \React \Term \ControlCodeParser ;
6
- use React \EventLoop \Factory ;
6
+ use React \EventLoop \Loop ;
7
7
use React \Stream \ReadableResourceStream ;
8
8
9
9
class FunctionalControlCodeParserTest extends TestCase
10
10
{
11
11
public function testPipingReadme ()
12
12
{
13
- $ loop = Factory::create ();
14
-
15
- $ input = new ReadableResourceStream (fopen (__DIR__ . '/../README.md ' , 'r+ ' ), $ loop );
13
+ $ input = new ReadableResourceStream (fopen (__DIR__ . '/../README.md ' , 'r+ ' ));
16
14
$ parser = new ControlCodeParser ($ input );
17
15
18
16
$ buffer = '' ;
19
17
$ parser ->on ('data ' , function ($ chunk ) use (&$ buffer ) {
20
18
$ buffer .= $ chunk ;
21
19
});
22
20
23
- $ loop -> run ();
21
+ Loop:: run ();
24
22
25
23
$ readme = str_replace (
26
24
"\n" ,
You can’t perform that action at this time.
0 commit comments