mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
@ -329,6 +329,15 @@ class BaseConsole
|
|||||||
return preg_replace('/\033\[[\d;?]*\w/', '', $string);
|
return preg_replace('/\033\[[\d;?]*\w/', '', $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the length of the string without ANSI color codes.
|
||||||
|
* @param string $string the string to measure
|
||||||
|
* @return int the length of the string not counting ANSI format characters
|
||||||
|
*/
|
||||||
|
public static function ansiStrlen($string) {
|
||||||
|
return mb_strlen(static::stripAnsiFormat($string));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an ANSI formatted string to HTML
|
* Converts an ANSI formatted string to HTML
|
||||||
*
|
*
|
||||||
@ -876,7 +885,7 @@ class BaseConsole
|
|||||||
} else {
|
} else {
|
||||||
self::$_progressPrefix = $prefix;
|
self::$_progressPrefix = $prefix;
|
||||||
}
|
}
|
||||||
$width -= mb_strlen($prefix);
|
$width -= static::ansiStrlen($prefix);
|
||||||
|
|
||||||
$percent = ($total == 0) ? 1 : $done / $total;
|
$percent = ($total == 0) ? 1 : $done / $total;
|
||||||
$info = sprintf("%d%% (%d/%d)", $percent * 100, $done, $total);
|
$info = sprintf("%d%% (%d/%d)", $percent * 100, $done, $total);
|
||||||
@ -888,7 +897,7 @@ class BaseConsole
|
|||||||
$info .= sprintf(' ETA: %d sec.', $rate * ($total - $done));
|
$info .= sprintf(' ETA: %d sec.', $rate * ($total - $done));
|
||||||
}
|
}
|
||||||
|
|
||||||
$width -= 3 + mb_strlen($info);
|
$width -= 3 + static::ansiStrlen($info);
|
||||||
// skipping progress bar on very small display or if forced to skip
|
// skipping progress bar on very small display or if forced to skip
|
||||||
if ($width < 5) {
|
if ($width < 5) {
|
||||||
static::stdout("\r$prefix$info ");
|
static::stdout("\r$prefix$info ");
|
||||||
|
|||||||
Reference in New Issue
Block a user