0.7.6
This commit is contained in:
@@ -5,11 +5,31 @@
|
||||
|
||||
class ProgressBar {
|
||||
|
||||
protected static $done = 0;
|
||||
protected static $total = 0;
|
||||
protected static $time_start;
|
||||
protected static $time_remain;
|
||||
protected static $time_update;
|
||||
protected static $total;
|
||||
protected static $done;
|
||||
protected static $message;
|
||||
|
||||
public static function display($message = null) {
|
||||
$string = "PROGRESS:".floor((self::$done/self::$total)*100);
|
||||
|
||||
$progress = self::$done/self::$total;
|
||||
$string = "PROGRESS:".round($progress*100,2);
|
||||
|
||||
if ($message === true) {
|
||||
$message = self::$message;
|
||||
}
|
||||
|
||||
if ($message) {
|
||||
if (time()-self::$time_update) { // only update the remaining time every 1 seconds
|
||||
$seconds = time() - self::$time_start;
|
||||
self::$time_remain = floor($seconds/$progress)-$seconds;
|
||||
self::$time_update = time();
|
||||
}
|
||||
$message = gmdate("H:i:s",self::$time_remain)." | ".$message;
|
||||
}
|
||||
|
||||
if ($message) {
|
||||
return "\n".$string."\n".$message;
|
||||
} elseif (!strpos(__FILE__,".app")) {
|
||||
@@ -17,10 +37,14 @@ class ProgressBar {
|
||||
} else {
|
||||
return "\n".$string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function start($total, $message = null) {
|
||||
self::$done = 0;
|
||||
self::$total = $total;
|
||||
self::$time_start = time();
|
||||
self::$message = $message;
|
||||
return $message."\n".self::display();
|
||||
}
|
||||
|
||||
@@ -30,6 +54,8 @@ class ProgressBar {
|
||||
}
|
||||
|
||||
public static function finish() {
|
||||
global $wopt_currstep;
|
||||
$wopt_currstep++;
|
||||
self::$done = 0;
|
||||
return "\n";
|
||||
}
|
||||
@@ -50,11 +76,14 @@ function getParents($zpath, $pathname) {
|
||||
}
|
||||
*/
|
||||
|
||||
function stringPrint($string) {
|
||||
echo $string.@str_repeat(" ", (10-strlen($string)));
|
||||
function stepString() {
|
||||
global $wopt_steps;
|
||||
global $wopt_currstep;
|
||||
return "Step ".$wopt_currstep." of ".$wopt_steps;
|
||||
}
|
||||
|
||||
function shortlabel($pathname, $max = 99, $pad = false) {
|
||||
|
||||
function shortlabel($pathname, $max = 99) {
|
||||
$basename = basename($pathname);
|
||||
$suffix = "(...).".pathinfo($basename,PATHINFO_EXTENSION);
|
||||
if (strlen($basename) > $max) {
|
||||
@@ -62,9 +91,6 @@ function shortlabel($pathname, $max = 99, $pad = false) {
|
||||
} else {
|
||||
$return = $basename;
|
||||
}
|
||||
if ($pad) {
|
||||
$return = $return.@str_repeat(" ", ($max-strlen($return)));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user