Skip to content

Commit

Permalink
[Console] fixed CS and simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Jul 1, 2011
1 parent a0eacbb commit 419d318
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions Shell.php
Expand Up @@ -26,7 +26,7 @@ class Shell
private $application;
private $history;
private $output;
private $hasreadline;
private $hasReadline;
private $prompt;

/**
Expand All @@ -41,7 +41,7 @@ class Shell
*/
public function __construct(Application $application)
{
$this->hasreadline = function_exists('readline') ? true : false;
$this->hasReadline = function_exists('readline') ? true : false;
$this->application = $application;
$this->history = getenv('HOME').'/.history_'.$application->getName();
$this->output = new ConsoleOutput();
Expand All @@ -56,7 +56,7 @@ public function run()
$this->application->setAutoExit(false);
$this->application->setCatchExceptions(true);

if ($this->hasreadline) {
if ($this->hasReadline) {
readline_read_history($this->history);
readline_completion_function(array($this, 'autocompleter'));
}
Expand All @@ -71,7 +71,7 @@ public function run()
break;
}

if ($this->hasreadline) {
if ($this->hasReadline) {
readline_add_history($command);
readline_write_history($this->history);
}
Expand Down Expand Up @@ -143,27 +143,14 @@ private function autocompleter($text, $position)
*/
private function readline()
{
$completeLine = '';
if ($this->hasreadline) {
$completeLine = readline($this->prompt);
if ($this->hasReadline) {
$line = readline($this->prompt);
} else {
$this->output->write($this->prompt);
while (true) {
$line = fgets(STDIN, 1024);
if (!$line && strlen($line) == 0) {
return false;
}

$line = rtrim($line);
$completeLine .= $line;
if (substr($line,-1) != '#') {
break;
} else {
$completeLine = substr($completeLine, 0, -1).PHP_EOL;
}
}
$line = fgets(STDIN, 1024);
$line = (!$line && strlen($line) == 0) ? false : rtrim($line);
}

return $completeLine;
return $line;
}
}

0 comments on commit 419d318

Please sign in to comment.