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 9, 2024
1 parent 00f297d commit 3016b2b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ 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);
Expand Down Expand Up @@ -78,6 +82,10 @@ are supported as defined in [ISO/IEC 2022](https://en.wikipedia.org/wiki/ISO/IEC
Each code sequence gets emitted with a dedicated event with its raw byte sequence:

```php
<?php

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

$stream->on('csi', function ($sequence) {
if ($sequence === "\x1B[A") {
echo 'cursor UP pressed';
Expand Down
10 changes: 3 additions & 7 deletions examples/random-colors.php
Original file line number Diff line number Diff line change
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 eact\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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3016b2b

Please sign in to comment.