Skip to content

Commit db17f53

Browse files
committed
Clear readline input prompt when ending stdio
1 parent 758d62f commit db17f53

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
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/Stdio.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +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
{
112+
$this->readline->setInput('')->setPrompt('')->clear();
111113
$this->input->pause();
112114
$this->input->close();
113115
$this->output->close();

0 commit comments

Comments
 (0)