Skip to content

Commit 17bb319

Browse files
committed
Merge pull request #21 from clue-labs/end
Clear readline input and restore TTY on end
2 parents 7fdc350 + f082b1f commit 17bb319

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

examples/login.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
$loop->run();
3030

3131
echo <<<EOT
32-
33-
32+
---------------------
3433
Confirmation:
3534
---------------------
3635
Username: $username

examples/periodic.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212

1313
$stdio->writeln('Will print periodic messages until you type "quit" or "exit"');
1414

15-
$stdio->on('line', function ($line) use ($stdio, $loop) {
15+
$stdio->on('line', function ($line) use ($stdio, $loop, &$timer) {
1616
$stdio->writeln('you just said: ' . $line . ' (' . strlen($line) . ')');
1717

1818
if ($line === 'quit' || $line === 'exit') {
19-
$loop->stop();
19+
$timer->cancel();
20+
$stdio->end();
2021
}
2122
});
2223

2324
// add some periodic noise
24-
$loop->addPeriodicTimer(2.0, function () use ($stdio) {
25+
$timer = $loop->addPeriodicTimer(2.0, function () use ($stdio) {
2526
$stdio->writeln('hello');
2627
});
2728

examples/spinner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
$stdio->on('line', function ($line) use ($stdio, &$tid, $loop, $spinner) {
2222
$stdio->overwrite('Processing... DONE');
23-
$stdio->getReadline()->setPrompt('');
2423

2524
$stdio->end();
2625
$spinner->pause();

src/Stdin.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public function pause()
4141
}
4242
}
4343

44+
public function close()
45+
{
46+
$this->pause();
47+
parent::close();
48+
}
49+
4450
public function __destruct()
4551
{
4652
$this->pause();

src/Stdio.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ public function end($data = null)
102102
$this->write($data);
103103
}
104104

105+
$this->readline->setInput('')->setPrompt('')->clear();
105106
$this->input->pause();
106107
$this->output->end();
107108
}
108109

109110
public function close()
110111
{
111-
$this->input->pause();
112+
$this->readline->setInput('')->setPrompt('')->clear();
112113
$this->input->close();
113114
$this->output->close();
114115
}

0 commit comments

Comments
 (0)