diff --git a/examples/login.php b/examples/login.php index 7d6f215..d6b08fa 100644 --- a/examples/login.php +++ b/examples/login.php @@ -29,8 +29,7 @@ $loop->run(); echo <<writeln('Will print periodic messages until you type "quit" or "exit"'); -$stdio->on('line', function ($line) use ($stdio, $loop) { +$stdio->on('line', function ($line) use ($stdio, $loop, &$timer) { $stdio->writeln('you just said: ' . $line . ' (' . strlen($line) . ')'); if ($line === 'quit' || $line === 'exit') { - $loop->stop(); + $timer->cancel(); + $stdio->end(); } }); // add some periodic noise -$loop->addPeriodicTimer(2.0, function () use ($stdio) { +$timer = $loop->addPeriodicTimer(2.0, function () use ($stdio) { $stdio->writeln('hello'); }); diff --git a/examples/spinner.php b/examples/spinner.php index 4f0de4d..24691af 100644 --- a/examples/spinner.php +++ b/examples/spinner.php @@ -20,7 +20,6 @@ $stdio->on('line', function ($line) use ($stdio, &$tid, $loop, $spinner) { $stdio->overwrite('Processing... DONE'); - $stdio->getReadline()->setPrompt(''); $stdio->end(); $spinner->pause(); diff --git a/src/Stdin.php b/src/Stdin.php index 387fe72..78d7740 100644 --- a/src/Stdin.php +++ b/src/Stdin.php @@ -41,6 +41,12 @@ public function pause() } } + public function close() + { + $this->pause(); + parent::close(); + } + public function __destruct() { $this->pause(); diff --git a/src/Stdio.php b/src/Stdio.php index e996146..2d4f002 100644 --- a/src/Stdio.php +++ b/src/Stdio.php @@ -102,13 +102,14 @@ public function end($data = null) $this->write($data); } + $this->readline->setInput('')->setPrompt('')->clear(); $this->input->pause(); $this->output->end(); } public function close() { - $this->input->pause(); + $this->readline->setInput('')->setPrompt('')->clear(); $this->input->close(); $this->output->close(); }