Skip to content

Instantly share code, notes, and snippets.

@dtjm
Created August 6, 2010 16:30
Show Gist options
  • Save dtjm/511579 to your computer and use it in GitHub Desktop.
Save dtjm/511579 to your computer and use it in GitHub Desktop.
Helper functions for doing terminal output
<?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);
}
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