A few new ANSI screen helpers

This commit is contained in:
Thomas Gelf 2013-10-22 15:51:49 +00:00 committed by root
parent 204e1941c6
commit 92ced41a77
1 changed files with 22 additions and 0 deletions

View File

@ -70,6 +70,28 @@ class AnsiScreen extends Screen
return $rows;
}
public function strlen($string)
{
return strlen($this->stripAnsiCodes($string));
}
public function stripAnsiCodes($string)
{
return preg_replace('/\e\[?.*?[\@-~]/', '', $string);
}
public function newlines($count = 1)
{
return str_repeat("\n", $count);
}
public function center($txt)
{
$len = $this->strlen($txt);
$width = floor(($this->getColumns() + $len) / 2) - $len;
return str_repeat(' ', $width) . $txt;
}
public function hasUtf8()
{
if ($this->isUtf8 === null) {