Skip to content

Commit

Permalink
Improve documentation and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yadaiio committed Feb 13, 2024
1 parent 00f297d commit 11adadd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -36,9 +36,13 @@ It wraps a given `ReadableStreamInterface` and exposes its plain data through
the same interface.

```php
<?php

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

$stdin = new React\Stream\ReadableResourceStream(STDIN);

$stream = new ControlCodeParser($stdin);
$stream = new Clue\React\Term\ControlCodeParser($stdin);

$stream->on('data', function ($chunk) {
var_dump($chunk);
Expand Down
10 changes: 3 additions & 7 deletions examples/random-colors.php
Expand Up @@ -11,10 +11,6 @@
// with random colors:
// $ phpunit --color=always | php random-colors.php

use Clue\React\Term\ControlCodeParser;
use React\Stream\ReadableResourceStream;
use React\Stream\WritableResourceStream;

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

if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
Expand All @@ -23,10 +19,10 @@
}

// process control codes from STDIN
$stdin = new ReadableResourceStream(STDIN);
$parser = new ControlCodeParser($stdin);
$stdin = new React\Stream\ReadableResourceStream(STDIN);
$parser = new Clue\React\Term\ControlCodeParser($stdin);

$stdout = new WritableResourceStream(STDOUT);
$stdout = new React\Stream\WritableResourceStream(STDOUT);

// pass all c0 codes through to output
$parser->on('c0', array($stdout, 'write'));
Expand Down
10 changes: 3 additions & 7 deletions examples/remove-codes.php
Expand Up @@ -8,10 +8,6 @@
// codes like this:
// $ phpunit --color=always | php remove-codes.php

use Clue\React\Term\ControlCodeParser;
use React\Stream\ReadableResourceStream;
use React\Stream\WritableResourceStream;

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

if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
Expand All @@ -20,11 +16,11 @@
}

// process control codes from STDIN
$stdin = new ReadableResourceStream(STDIN);
$parser = new ControlCodeParser($stdin);
$stdin = new React\Stream\ReadableResourceStream(STDIN);
$parser = new Clue\React\Term\ControlCodeParser($stdin);

// pipe data from STDIN to STDOUT without any codes
$stdout = new WritableResourceStream(STDOUT);
$stdout = new React\Stream\WritableResourceStream(STDOUT);
$parser->pipe($stdout);

// only forward \r, \n and \t
Expand Down
7 changes: 2 additions & 5 deletions examples/stdin-codes.php
Expand Up @@ -9,9 +9,6 @@
// codes like this:
// $ phpunit --color=always | php stdin-codes.php

use Clue\React\Term\ControlCodeParser;
use React\Stream\ReadableResourceStream;

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

if (function_exists('posix_isatty') && posix_isatty(STDIN)) {
Expand All @@ -20,8 +17,8 @@
}

// process control codes from STDIN
$stdin = new ReadableResourceStream(STDIN);
$parser = new ControlCodeParser($stdin);
$stdin = new React\Stream\ReadableResourceStream(STDIN);
$parser = new Clue\React\Term\ControlCodeParser($stdin);

$decoder = function ($code) {
echo 'Code:';
Expand Down

0 comments on commit 11adadd

Please sign in to comment.