Skip to content

Instantly share code, notes, and snippets.

@twesolowski
Created December 19, 2013 17:23
Show Gist options
  • Save twesolowski/8042953 to your computer and use it in GitHub Desktop.
Save twesolowski/8042953 to your computer and use it in GitHub Desktop.
CliCounter
<?php
class CliCounter{
static $text=null;
static $bs = "\x08";
static $loading = array("[\\]", "[|]","[/]", "[|]");
static $loader = false;
static $date = false;
static $dateFormat = "Y-m-d H:i:s";
static $i=0;
public static function prnt($text){
if(self::$loader === true){
$text = self::$loading[(self::$i++)%4].' '.$text;
}
if(self::$date){
$text = date(self::$dateFormat).' '.$text;
}
print(str_repeat(self::$bs, strlen(self::$text)));
$text = str_pad($text, strlen(trim(self::$text)), " ");
print($text);
self::$text = $text;
}
}
<?php
CliTool::$loader = true;
CliTool::$date = true;
echo "Waiting: ";
for($i=0;$i<=100;$i++){
CliTool::prnt($i.'/100');
usleep(500000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment