Created
July 10, 2012 10:12
-
-
Save slywalker/3082470 to your computer and use it in GitHub Desktop.
CakePHP AppShell::progressBar()
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 | |
class AppShell extends Shell { | |
public function progressBar($current, $total, $size = 50) { | |
$perc = intval(($current / $total) * 100); | |
for ($i = strlen($perc); $i <= 4; $i++) { | |
$perc = ' ' . $perc; | |
} | |
$total_size = $size + $i + 3; | |
if ($current > 0) { | |
for ($place = $total_size; $place > 0; $place--) { | |
echo "\x08"; | |
} | |
} | |
for ($place = 0; $place <= $size; $place++) { | |
if ($place <= ($current / $total * $size)) { | |
echo "\033[42m \033[0m"; | |
} else { | |
echo "\033[47m \033[0m"; | |
} | |
} | |
echo " $perc%"; | |
if ($current == $total) { | |
echo PHP_EOL; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment