Created
August 6, 2010 16:30
-
-
Save dtjm/511579 to your computer and use it in GitHub Desktop.
Helper functions for doing terminal output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function message($text) { | |
printf('%-48s: ', $text); | |
} | |
function succeed($text = ' OK ') { | |
$esc = chr(27); | |
echo "[{$esc}[0;33m$text{$esc}[0m$esc" . "\]\n"; | |
} | |
function fail($text = 'FAIL') { | |
$esc = chr(27); | |
echo "[{$esc}[0;31m$text{$esc}[0m$esc" . "\]\n"; | |
} | |
function checkSuccess($retVal) { | |
$retVal == 0 ? succeed() : fail(); | |
} | |
function readline() { | |
$fp = fopen('php://stdin', 'r'); | |
return fgets($fp, 1024); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
message(){ | |
printf "%-48b" "$1" | |
} | |
function succeed($text = ' OK ') { | |
$esc = chr(27); | |
echo "[{$esc}[0;33m$text{$esc}[0m$esc" . "\]\n"; | |
} | |
function fail($text = 'FAIL') { | |
$esc = chr(27); | |
echo "[{$esc}[0;31m$text{$esc}[0m$esc" . "\]\n"; | |
$args = func_get_args(); | |
array_shift($args); | |
foreach($args as $detail) | |
echo "=> $detail\n"; | |
exit(1); | |
} | |
function checkSuccess($success) { | |
$success ? succeed() : fail(); | |
} | |
function readlinePassword($prompt) | |
{ | |
system('stty -echo'); | |
$line = readline($prompt); | |
system('stty echo'); | |
echo "\n"; | |
return $line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment