Skip to content

Commit

Permalink
Merge pull request #21 from clue-labs/end
Browse files Browse the repository at this point in the history
Clear readline input and restore TTY on end
  • Loading branch information
clue committed May 17, 2015
2 parents 7fdc350 + f082b1f commit 17bb319
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 1 addition & 2 deletions examples/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
$loop->run();

echo <<<EOT
---------------------
Confirmation:
---------------------
Username: $username
Expand Down
7 changes: 4 additions & 3 deletions examples/periodic.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

$stdio->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');
});

Expand Down
1 change: 0 additions & 1 deletion examples/spinner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/Stdin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public function pause()
}
}

public function close()
{
$this->pause();
parent::close();
}

public function __destruct()
{
$this->pause();
Expand Down
3 changes: 2 additions & 1 deletion src/Stdio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 17bb319

Please sign in to comment.