Skip to content

Commit 3659e89

Browse files
authored
Merge pull request #100 from clue-labs/docs
Improve code examples and documentation
2 parents 925d5ba + 0233e6f commit 3659e89

8 files changed

+41
-54
lines changed

README.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# clue/reactphp-stdio
22

33
[![CI status](https://github.com/clue/reactphp-stdio/workflows/CI/badge.svg)](https://github.com/clue/reactphp-stdio/actions)
4-
[![Packagist downloads](https://img.shields.io/packagist/dt/clue/stdio-react?color=blue&label=installs)](https://packagist.org/packages/clue/stdio-react)
4+
[![installs on Packagist](https://img.shields.io/packagist/dt/clue/stdio-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/stdio-react)
55

66
Async, event-driven and UTF-8 aware console input & output (STDIN, STDOUT) for
7-
truly interactive CLI applications, built on top of [ReactPHP](https://reactphp.org).
7+
truly interactive CLI applications, built on top of [ReactPHP](https://reactphp.org/).
88

99
You can use this library to build truly interactive and responsive command
1010
line (CLI) applications, that immediately react when the user types in
@@ -18,18 +18,18 @@ without requiring any extensions or special installation.
1818
* [Support us](#support-us)
1919
* [Quickstart example](#quickstart-example)
2020
* [Usage](#usage)
21-
* [Stdio](#stdio)
22-
* [Output](#output)
23-
* [Input](#input)
24-
* [Prompt](#prompt)
25-
* [Echo](#echo)
26-
* [Input buffer](#input-buffer)
27-
* [Cursor](#cursor)
28-
* [History](#history)
29-
* [Autocomplete](#autocomplete)
30-
* [Keys](#keys)
31-
* [Bell](#bell)
32-
* [Readline](#readline)
21+
* [Stdio](#stdio)
22+
* [Output](#output)
23+
* [Input](#input)
24+
* [Prompt](#prompt)
25+
* [Echo](#echo)
26+
* [Input buffer](#input-buffer)
27+
* [Cursor](#cursor)
28+
* [History](#history)
29+
* [Autocomplete](#autocomplete)
30+
* [Keys](#keys)
31+
* [Bell](#bell)
32+
* [~~Readline~~](#readline)
3333
* [Pitfalls](#pitfalls)
3434
* [Install](#install)
3535
* [Tests](#tests)
@@ -51,8 +51,11 @@ Let's take these projects to the next level together! 🚀
5151
Once [installed](#install), you can use the following code to present a prompt in a CLI program:
5252

5353
```php
54-
$stdio = new Stdio();
54+
<?php
5555

56+
require __DIR__ . '/vendor/autoload.php';
57+
58+
$stdio = new Clue\React\Stdio\Stdio();
5659
$stdio->setPrompt('Input > ');
5760

5861
$stdio->on('data', function ($line) use ($stdio) {
@@ -76,7 +79,7 @@ It is responsible for orchestrating the input and output streams
7679
by registering and forwarding the corresponding events.
7780

7881
```php
79-
$stdio = new Stdio();
82+
$stdio = new Clue\React\Stdio\Stdio();
8083
```
8184

8285
This class takes an optional `LoopInterface|null $loop` parameter that can be used to
@@ -567,7 +570,9 @@ enable or disable emitting the BELL signal when using a disabled function:
567570
$stdio->setBell(false);
568571
```
569572

570-
### Readline
573+
### ~~Readline~~
574+
575+
> Deprecated since v2.3.0, see [`Stdio`](#stdio) instead.
571576
572577
The deprecated `Readline` class is responsible for reacting to user input and
573578
presenting a prompt to the user. It does so by reading individual bytes from the
@@ -630,7 +635,7 @@ ob_start(function ($chunk) use ($stdio) {
630635

631636
## Install
632637

633-
The recommended way to install this library is [through Composer](https://getcomposer.org).
638+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
634639
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
635640

636641
This project follows [SemVer](https://semver.org/).
@@ -645,7 +650,7 @@ See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
645650
This project aims to run on any platform and thus does not require any PHP
646651
extensions and supports running on legacy PHP 5.3 through current PHP 8+ and
647652
HHVM.
648-
It's *highly recommended to use PHP 7+* for this project.
653+
It's *highly recommended to use the latest supported PHP version* for this project.
649654

650655
Internally, it will use the `ext-mbstring` to count and measure string sizes.
651656
If this extension is missing, then this library will use a slighty slower Regex
@@ -660,22 +665,19 @@ Input line editing is handled entirely within this library and does not rely on
660665
Installing `ext-readline` is entirely optional.
661666

662667
Note that *Microsoft Windows is not supported*.
663-
Due to platform inconsistencies, PHP does not provide support for reading from
664-
standard console input without blocking.
668+
Due to platform constraints, PHP does not provide support for reading from
669+
standard console input without blocking on Windows.
665670
Unfortunately, until the underlying PHP feature request is implemented (which
666671
is unlikely to happen any time soon), there's little we can do in this library.
667-
A work-around for this remains unknown.
668-
Your only option would be to entirely
669-
[disable interactive input for Microsoft Windows](https://github.com/clue/psocksd/commit/c2f2f90ffc8ebf8233839ba2f3553f2698930125).
670-
However this package does work on [`Windows Subsystem for Linux`](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
671-
(or WSL) without issues. We suggest [installing WSL](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
672+
However, this package does work on Windows Subsystem for Linux (or WSL) without
673+
issues. We suggest [installing WSL](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide)
672674
when you want to run this package on Windows.
673675
See also [#18](https://github.com/clue/reactphp-stdio/issues/18) for more details.
674676

675677
## Tests
676678

677679
To run the test suite, you first need to clone this repo and then install all
678-
dependencies [through Composer](https://getcomposer.org):
680+
dependencies [through Composer](https://getcomposer.org/):
679681

680682
```bash
681683
$ composer install
@@ -684,7 +686,7 @@ $ composer install
684686
To run the test suite, go to the project root and run:
685687

686688
```bash
687-
$ php vendor/bin/phpunit
689+
$ vendor/bin/phpunit
688690
```
689691

690692
## License

examples/01-periodic.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22

3-
use Clue\React\Stdio\Stdio;
43
use React\EventLoop\Loop;
54

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

8-
$stdio = new Stdio();
7+
$stdio = new Clue\React\Stdio\Stdio();
98

109
$stdio->write('Will print periodic messages until you submit anything' . PHP_EOL);
1110

examples/02-interactive.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php
22

3-
use Clue\React\Stdio\Stdio;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$stdio = new Stdio();
8-
5+
$stdio = new Clue\React\Stdio\Stdio();
96
$stdio->setPrompt('> ');
107

118
// limit history to HISTSIZE env

examples/03-commander.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
<?php
22

3-
use Clue\React\Stdio\Stdio;
4-
use Clue\Arguments;
5-
use Clue\Commander\Router;
6-
use Clue\Commander\NoRouteFoundException;
7-
83
require __DIR__ . '/../vendor/autoload.php';
94

10-
$stdio = new Stdio();
5+
$stdio = new Clue\React\Stdio\Stdio();
116
$stdio->setPrompt('> ');
127

138
// limit history to HISTSIZE env
@@ -21,7 +16,7 @@
2116
}
2217

2318
// register all available commands and their arguments
24-
$router = new Router();
19+
$router = new Clue\Commander\Router();
2520
$router->add('exit | quit', function() use ($stdio) {
2621
$stdio->end();
2722
});
@@ -54,8 +49,8 @@
5449
}
5550

5651
try {
57-
$args = Arguments\split($line);
58-
} catch (Arguments\UnclosedQuotesException $e) {
52+
$args = Clue\Arguments\split($line);
53+
} catch (Clue\Arguments\UnclosedQuotesException $e) {
5954
$stdio->write('Error: Invalid command syntax (unclosed quotes)' . PHP_EOL);
6055
return;
6156
}
@@ -67,7 +62,7 @@
6762

6863
try {
6964
$router->handleArgs($args);
70-
} catch (NoRouteFoundException $e) {
65+
} catch (Clue\Commander\NoRouteFoundException $e) {
7166
$stdio->write('Error: Invalid command usage' . PHP_EOL);
7267
}
7368
});

examples/04-bindings.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22

3-
use Clue\React\Stdio\Stdio;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$stdio = new Stdio();
5+
$stdio = new Clue\React\Stdio\Stdio();
86
$stdio->setPrompt('> ');
97

108
// add some special key bindings

examples/05-cursor.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22

3-
use Clue\React\Stdio\Stdio;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$stdio = new Stdio();
5+
$stdio = new Clue\React\Stdio\Stdio();
86

97
$value = 10;
108
$stdio->on("\033[A", function () use (&$value, $stdio) {

examples/11-login.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22

3-
use Clue\React\Stdio\Stdio;
4-
53
require __DIR__ . '/../vendor/autoload.php';
64

7-
$stdio = new Stdio();
5+
$stdio = new Clue\React\Stdio\Stdio();
86
$stdio->setPrompt('Username: ');
97

108
$first = true;

src/Readline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use React\Stream\WritableStreamInterface;
1212

1313
/**
14-
* @deprecated use Stdio instead
14+
* @deprecated 2.3.0 Use `Stdio` instead
1515
* @see Stdio
1616
*/
1717
class Readline extends EventEmitter implements ReadableStreamInterface

0 commit comments

Comments
 (0)