Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alistair Kearney committed Jul 1, 2016
1 parent 324fa20 commit 538fcfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/Lib/Message.php
Expand Up @@ -42,7 +42,8 @@ class Message
'light gray' => '47',
];

public function __get($name){
public function __get($name)
{
return $this->$name;
}

Expand All @@ -54,14 +55,15 @@ public function __construct($message = null)
$this->dateFormat("H:i:s > ");
}

public function message($message){
public function message($message)
{
$this->message = $message;
return $this;
}

public function foreground($colour)
{
if(!array_key_exists($colour, self::$foregroundColours)) {
if (!array_key_exists($colour, self::$foregroundColours)) {
throw new \Exception('No such foreground colour `'.$colour.'`');
}
$this->foreground = $colour;
Expand All @@ -70,7 +72,7 @@ public function foreground($colour)

public function background($colour)
{
if(!array_key_exists($colour, self::$backgroundColours)) {
if (!array_key_exists($colour, self::$backgroundColours)) {
throw new \Exception('No such background colour `'.$colour.'`');
}
$this->background = $colour;
Expand Down Expand Up @@ -118,4 +120,4 @@ public function display($target=STDOUT)
)
);
}
}
}
12 changes: 5 additions & 7 deletions src/Lib/Utils.php
Expand Up @@ -24,32 +24,30 @@ public static function promptForInput($prompt, $silent = false, $default = null,
throw new \Exception("bash cannot be invoked from PHP. 'silent' flag cannot be used.");
}

if(!($prompt instanceof Message)) {
if (!($prompt instanceof Message)) {
$prompt = new Message($prompt);
}

$prompt->message(sprintf(
"%s%s: ", $prompt->message, (!is_null($default) ? " [{$default}]" : null)
));

do{
do {
$prompt->display();

if($silent) {
if ($silent) {
$command = "/usr/bin/env bash -c 'read -s in && echo \$in'";
$input = shell_exec($command);
echo PHP_EOL;

} else {
$input = fgets(STDIN, 256);
}

$input = trim($input);
if(strlen(trim($input)) == 0 && !is_null($default)){
if (strlen(trim($input)) == 0 && !is_null($default)) {
$input = $default;
}

}while($validator instanceof \Closure && !$validator($input));
} while ($validator instanceof \Closure && !$validator($input));

return $input;
}
Expand Down

0 comments on commit 538fcfc

Please sign in to comment.