Skip to content

Commit 11363e3

Browse files
authored
Merge pull request #64 from clue-labs/cleanup
Remove deprecated functionality
2 parents f751e05 + 56833a4 commit 11363e3

File tree

5 files changed

+12
-202
lines changed

5 files changed

+12
-202
lines changed

README.md

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ built on top of for [ReactPHP](https://reactphp.org).
1717
* [Cursor](#cursor)
1818
* [History](#history)
1919
* [Autocomplete](#autocomplete)
20-
* [Advanced](#advanced)
21-
* [Stdout](#stdout)
22-
* [Stdin](#stdin)
2320
* [Pitfalls](#pitfalls)
2421
* [Install](#install)
2522
* [Tests](#tests)
@@ -82,23 +79,6 @@ $stdio->write('hello');
8279
$stdio->write(" world\n");
8380
```
8481

85-
[Deprecated] The `writeln($line)` method can be used to print a line to console output.
86-
A trailing newline will be added automatically.
87-
88-
```php
89-
// deprecated
90-
$stdio->writeln('hello world');
91-
```
92-
93-
[Deprecated] The `overwrite($text)` method can be used to overwrite/replace the last
94-
incomplete line with the given text:
95-
96-
```php
97-
$stdio->write('Loading…');
98-
// deprecated
99-
$stdio->overwrite('Done!');
100-
```
101-
10282
Alternatively, you can also use the `Stdio` as a writable stream.
10383
You can `pipe()` any readable stream into this stream.
10484

@@ -126,19 +106,6 @@ streams.
126106
You can control various aspects of the console input through the [`Readline`](#readline),
127107
so read on..
128108

129-
[Deprecated] It will emit a `line` event for every line read from console input.
130-
The event will contain the input buffer as-is, without the trailing newline.
131-
You can register any number of event handlers like this:
132-
133-
```php
134-
// deprecated
135-
$stdio->on('line', function ($line) {
136-
if ($line === 'start') {
137-
doSomething();
138-
}
139-
});
140-
```
141-
142109
### Readline
143110

144111
The [`Readline`](#readline) class is responsible for reacting to user input and presenting a prompt to the user.
@@ -486,51 +453,6 @@ disable the autocomplete function:
486453
$readline->setAutocomplete(null);
487454
```
488455

489-
### Advanced
490-
491-
#### Stdout
492-
493-
[Deprecated] The `Stdout` represents a `WritableStream` and is responsible for handling console output.
494-
495-
Interfacing with it directly is *not recommended* and considered *advanced usage*.
496-
497-
If you want to print some text to console output, use the [`Stdio::write()`](#output) instead:
498-
499-
```php
500-
$stdio->write('hello');
501-
```
502-
503-
Should you need to interface with the `Stdout`, you can access the current instance through the [`Stdio`](#stdio):
504-
505-
```php
506-
// deprecated
507-
$stdout = $stdio->getOutput();
508-
```
509-
510-
#### Stdin
511-
512-
[Deprecated] The `Stdin` represents a `ReadableStream` and is responsible for handling console input.
513-
514-
Interfacing with it directly is *not recommended* and considered *advanced usage*.
515-
516-
If you want to read a line from console input, use the [`Stdio::on()`](#input) instead:
517-
518-
```php
519-
$stdio->on('data', function ($line) use ($stdio) {
520-
$line = rtrim($line, "\r\n");
521-
$stdio->write('You said "' . $line . '"' . PHP_EOL);
522-
});
523-
```
524-
525-
Should you need to interface with the `Stdin`, you can access the current instance through the [`Stdio`](#stdio):
526-
527-
You can access the current instance through the [`Stdio`](#stdio):
528-
529-
```php
530-
// deprecated
531-
$stdin = $stdio->getInput();
532-
```
533-
534456
## Pitfalls
535457

536458
The [`Readline`](#readline) has to redraw the current user

src/Stdin.php renamed to src/Io/Stdin.php

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

3-
namespace Clue\React\Stdio;
3+
namespace Clue\React\Stdio\Io;
44

55
use React\Stream\Stream;
66
use React\EventLoop\LoopInterface;
77

88
/**
9-
* @deprecated
9+
* @internal
1010
*/
1111
class Stdin extends Stream
1212
{

src/Stdout.php renamed to src/Io/Stdout.php

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

3-
namespace Clue\React\Stdio;
3+
namespace Clue\React\Stdio\Io;
44

55
use React\Stream\WritableStream;
66

77
/**
8-
* @deprecated
8+
* @internal
99
*/
1010
class Stdout extends WritableStream
1111
{

src/Stdio.php

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Clue\React\Stdio;
44

5+
use Clue\React\Stdio\Io\Stdin;
6+
use Clue\React\Stdio\Io\Stdout;
57
use Evenement\EventEmitter;
6-
use React\Stream\DuplexStreamInterface;
78
use React\EventLoop\LoopInterface;
9+
use React\Stream\DuplexStreamInterface;
810
use React\Stream\ReadableStreamInterface;
9-
use React\Stream\WritableStreamInterface;
1011
use React\Stream\Util;
12+
use React\Stream\WritableStreamInterface;
1113

1214
class Stdio extends EventEmitter implements DuplexStreamInterface
1315
{
@@ -47,9 +49,6 @@ public function __construct(LoopInterface $loop, ReadableStreamInterface $input
4749

4850
// emit data with trailing newline in order to preserve readable API
4951
$that->emit('data', array($line . PHP_EOL));
50-
51-
// emit custom line event for ease of use
52-
$that->emit('line', array($line, $that));
5352
});
5453

5554
// handle all input events (readline forwards all input events)
@@ -162,28 +161,6 @@ public function write($data)
162161
}
163162
}
164163

165-
/**
166-
* @deprecated
167-
*/
168-
public function writeln($line)
169-
{
170-
$this->write($line . PHP_EOL);
171-
}
172-
173-
/**
174-
* @deprecated
175-
*/
176-
public function overwrite($data = '')
177-
{
178-
if ($this->incompleteLine !== '') {
179-
// move one line up, move to start of line and clear everything
180-
$data = "\033[A\r\033[K" . $data;
181-
$this->incompleteLine = '';
182-
}
183-
184-
$this->write($data);
185-
}
186-
187164
public function end($data = null)
188165
{
189166
if ($this->ending) {
@@ -217,22 +194,6 @@ public function close()
217194
$this->output->close();
218195
}
219196

220-
/**
221-
* @deprecated
222-
*/
223-
public function getInput()
224-
{
225-
return $this->input;
226-
}
227-
228-
/**
229-
* @deprecated
230-
*/
231-
public function getOutput()
232-
{
233-
return $this->output;
234-
}
235-
236197
public function getReadline()
237198
{
238199
return $this->readline;

tests/StdioTest.php

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testCtorDefaultArgs()
2121
$stdio->close();
2222
}
2323

24-
public function testCtorArgsWillBeReturnedByGetters()
24+
public function testCtorReadlineArgWillBeReturnedBygetReadline()
2525
{
2626
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
2727
$output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
@@ -31,8 +31,6 @@ public function testCtorArgsWillBeReturnedByGetters()
3131

3232
$stdio = new Stdio($this->loop, $input, $output, $readline);
3333

34-
$this->assertSame($input, $stdio->getInput());
35-
$this->assertSame($output, $stdio->getOutput());
3634
$this->assertSame($readline, $stdio->getReadline());
3735
}
3836

@@ -168,77 +166,7 @@ public function testWriteAfterReadlineInputWillClearReadlineWriteOutputAndRestor
168166
$buffer .= $data;
169167
}));
170168

171-
$stdio->writeln('test');
172-
173-
$this->assertEquals("\r\033[K" . "test\n" . "> input", $buffer);
174-
}
175-
176-
public function testOverwriteWillClearReadlineMoveToPreviousLineWriteOutputAndRestoreReadline()
177-
{
178-
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
179-
$output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
180-
181-
//$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock();
182-
$readline = new Readline($input, $output);
183-
$readline->setPrompt('> ');
184-
$readline->setInput('input');
185-
186-
$stdio = new Stdio($this->loop, $input, $output, $readline);
187-
188-
$stdio->write('first');
189-
190-
$buffer = '';
191-
$output->expects($this->any())->method('write')->will($this->returnCallback(function ($data) use (&$buffer) {
192-
$buffer .= $data;
193-
}));
194-
195-
$stdio->overwrite('overwrite');
196-
197-
$this->assertEquals("\r\033[K" . "\033[A" . "\r\033[K" . "overwrite\n" . "> input", $buffer);
198-
}
199-
200-
public function testOverwriteAfterNewlineWillClearReadlineAndWriteOutputAndRestoreReadline()
201-
{
202-
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
203-
$output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
204-
205-
//$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock();
206-
$readline = new Readline($input, $output);
207-
$readline->setPrompt('> ');
208-
$readline->setInput('input');
209-
210-
$stdio = new Stdio($this->loop, $input, $output, $readline);
211-
212-
$stdio->write("first\n");
213-
214-
$buffer = '';
215-
$output->expects($this->any())->method('write')->will($this->returnCallback(function ($data) use (&$buffer) {
216-
$buffer .= $data;
217-
}));
218-
219-
$stdio->overwrite('overwrite');
220-
221-
$this->assertEquals("\r\033[K" . "overwrite\n" . "> input", $buffer);
222-
}
223-
224-
public function testWriteLineWillClearReadlineWriteOutputAndRestoreReadline()
225-
{
226-
$input = $this->getMockBuilder('React\Stream\ReadableStreamInterface')->getMock();
227-
$output = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock();
228-
229-
//$readline = $this->getMockBuilder('Clue\React\Stdio\Readline')->disableOriginalConstructor()->getMock();
230-
$readline = new Readline($input, $output);
231-
$readline->setPrompt('> ');
232-
$readline->setInput('input');
233-
234-
$stdio = new Stdio($this->loop, $input, $output, $readline);
235-
236-
$buffer = '';
237-
$output->expects($this->any())->method('write')->will($this->returnCallback(function ($data) use (&$buffer) {
238-
$buffer .= $data;
239-
}));
240-
241-
$stdio->writeln('test');
169+
$stdio->write("test\n");
242170

243171
$this->assertEquals("\r\033[K" . "test\n" . "> input", $buffer);
244172
}
@@ -260,8 +188,8 @@ public function testWriteTwoLinesWillClearReadlineWriteOutputAndRestoreReadline(
260188
$buffer .= $data;
261189
}));
262190

263-
$stdio->writeln('hello');
264-
$stdio->writeln('world');
191+
$stdio->write("hello\n");
192+
$stdio->write("world\n");
265193

266194
$this->assertEquals("\r\033[K" . "hello\n" . "> input" . "\r\033[K" . "world\n" . "> input", $buffer);
267195
}
@@ -454,7 +382,6 @@ public function testDataEventWillBeForwarded()
454382
$stdio = new Stdio($this->loop, $input, $output, $readline);
455383

456384
$stdio->on('data', $this->expectCallableOnceWith("hello\n"));
457-
$stdio->on('line', $this->expectCallableOnceWith('hello'));
458385

459386
$readline->emit('data', array('hello'));
460387
}

0 commit comments

Comments
 (0)