Skip to content

Instantly share code, notes, and snippets.

@slywalker
Created July 10, 2012 10:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slywalker/3082470 to your computer and use it in GitHub Desktop.
Save slywalker/3082470 to your computer and use it in GitHub Desktop.
CakePHP AppShell::progressBar()
<?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