193        $this->max_x = 
$x - 1;
 
  194        $this->max_y = 
$y - 1;
 
  195        $this->x = $this->y = 0;
 
  196        $this->history = $this->history_attrs = array();
 
  197        $this->attr_row = array_fill(0, $this->max_x + 2, $this->base_attr_cell);
 
  198        $this->screen = array_fill(0, $this->max_y + 1, 
'');
 
  199        $this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row);
 
  235        $this->tokenization = array(
'');
 
  237            if (strlen($this->ansi)) {
 
  243                    case $this->ansi == 
"\x1B=":
 
  246                    case strlen($this->ansi) == 2 && $chr >= 64 && $chr <= 95 && $chr != ord(
'['):
 
  247                    case strlen($this->ansi) > 2 && $chr >= 64 && $chr <= 126:
 
  253                $this->tokenization[] = 
'';
 
  255                switch ($this->ansi) {
 
  259                        $this->x = $this->y = 0;
 
  262                        $this->history = array_merge($this->history, array_slice(array_splice($this->screen, $this->y + 1), 0, $this->old_y));
 
  263                        $this->screen = array_merge($this->screen, array_fill($this->y, $this->max_y, 
''));
 
  265                        $this->history_attrs = array_merge($this->history_attrs, array_slice(array_splice($this->attrs, $this->y + 1), 0, $this->old_y));
 
  266                        $this->attrs = array_merge($this->attrs, array_fill($this->y, $this->max_y, $this->attr_row));
 
  268                        if (count($this->history) == $this->max_history) {
 
  269                            array_shift($this->history);
 
  270                            array_shift($this->history_attrs);
 
  273                        $this->screen[
$this->y] = substr($this->screen[$this->y], 0, $this->x);
 
  275                        array_splice($this->attrs[$this->y], $this->x + 1, $this->max_x - $this->x, array_fill($this->x, $this->max_x - $this->x - 1, $this->base_attr_cell));
 
  278                        $this->screen[
$this->y] = str_repeat(
' ', $this->x);
 
  291                            case preg_match(
'#\x1B\[(\d+)B#', $this->ansi, $match): 
 
  293                                $this->y+= $match[1];
 
  295                            case preg_match(
'#\x1B\[(\d+);(\d+)H#', $this->ansi, $match): 
 
  298                                $this->x = $match[2] - 1;
 
  299                                $this->y = $match[1] - 1;
 
  301                            case preg_match(
'#\x1B\[(\d+)C#', $this->ansi, $match): 
 
  303                                $this->x+= $match[1];
 
  305                            case preg_match(
'#\x1B\[(\d+)D#', $this->ansi, $match): 
 
  307                                $this->x-= $match[1];
 
  309                            case preg_match(
'#\x1B\[(\d+);(\d+)r#', $this->ansi, $match): 
 
  311                            case preg_match(
'#\x1B\[(\d*(?:;\d*)*)m#', $this->ansi, $match): 
 
  313                                $mods = explode(
';', $match[1]);
 
  314                                foreach ($mods as $mod) {
 
  341                                                case 30: $front = 
'black'; 
break;
 
  342                                                case 31: $front = 
'red'; 
break;
 
  343                                                case 32: $front = 
'green'; 
break;
 
  344                                                case 33: $front = 
'yellow'; 
break;
 
  345                                                case 34: $front = 
'blue'; 
break;
 
  346                                                case 35: $front = 
'magenta'; 
break;
 
  347                                                case 36: $front = 
'cyan'; 
break;
 
  348                                                case 37: $front = 
'white'; 
break;
 
  350                                                case 40: $back = 
'black'; 
break;
 
  351                                                case 41: $back = 
'red'; 
break;
 
  352                                                case 42: $back = 
'green'; 
break;
 
  353                                                case 43: $back = 
'yellow'; 
break;
 
  354                                                case 44: $back = 
'blue'; 
break;
 
  355                                                case 45: $back = 
'magenta'; 
break;
 
  356                                                case 46: $back = 
'cyan'; 
break;
 
  357                                                case 47: $back = 
'white'; 
break;
 
  376            $this->tokenization[count($this->tokenization) - 1].= 
$source[
$i];
 
  388                        $this->screen[
$this->y] = substr_replace(
 
  389                            $this->screen[$this->y],
 
  399                    $this->tokenization[count($this->tokenization) - 1] = substr($this->tokenization[count($this->tokenization) - 1], 0, -1);
 
  403                    $this->ansi.= 
"\x1B";
 
  407                    if ($this->x > strlen($this->screen[$this->y])) {
 
  408                        $this->screen[
$this->y] = str_repeat(
' ', $this->x);
 
  410                    $this->screen[
$this->y] = substr_replace(
 
  411                        $this->screen[$this->y],
 
  417                    if ($this->x > $this->max_x) {
 
  440        while ($this->y >= $this->max_y) {
 
  441            $this->history = array_merge($this->history, array(array_shift($this->screen)));
 
  442            $this->screen[] = 
'';
 
  444            $this->history_attrs = array_merge($this->history_attrs, array(array_shift($this->attrs)));
 
  445            $this->attrs[] = $this->attr_row;
 
  447            if (count($this->history) >= $this->max_history) {
 
  448                array_shift($this->history);
 
  449                array_shift($this->history_attrs);
 
  467        if ($last_attr != $cur_attr) {
 
  469            if ($last_attr->foreground != $cur_attr->foreground) {
 
  470                if ($cur_attr->foreground != 
'white') {
 
  471                    $open.= 
'<span style="color: ' . $cur_attr->foreground . 
'">';
 
  473                if ($last_attr->foreground != 
'white') {
 
  474                    $close = 
'</span>' . $close;
 
  477            if ($last_attr->background != $cur_attr->background) {
 
  478                if ($cur_attr->background != 
'black') {
 
  479                    $open.= 
'<span style="background: ' . $cur_attr->background . 
'">';
 
  481                if ($last_attr->background != 
'black') {
 
  482                    $close = 
'</span>' . $close;
 
  485            if ($last_attr->bold != $cur_attr->bold) {
 
  486                if ($cur_attr->bold) {
 
  489                    $close = 
'</b>' . $close;
 
  492            if ($last_attr->underline != $cur_attr->underline) {
 
  493                if ($cur_attr->underline) {
 
  496                    $close = 
'</u>' . $close;
 
  499            if ($last_attr->blink != $cur_attr->blink) {
 
  500                if ($cur_attr->blink) {
 
  503                    $close = 
'</blink>' . $close;
 
  509        $output.= htmlspecialchars($char);
 
  523        $last_attr = $this->base_attr_cell;
 
  524        for (
$i = 0; 
$i <= $this->max_y; 
$i++) {
 
  525            for ($j = 0; $j <= $this->max_x; $j++) {
 
  526                $cur_attr = $this->attrs[
$i][$j];
 
  527                $output.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->screen[
$i][$j]) ? $this->screen[
$i][$j] : 
'');
 
  528                $last_attr = $this->attrs[
$i][$j];
 
  534        $output.= $this->_processCoordinate($last_attr, $this->base_attr_cell, 
'');
 
  546        return '<pre width="' . ($this->max_x + 1) . 
'" style="color: white; background: black">' . $this->_getScreen() . 
'</pre>';
 
  558        $last_attr = $this->base_attr_cell;
 
  559        for (
$i = 0; 
$i < count($this->history); 
$i++) {
 
  560            for ($j = 0; $j <= $this->max_x + 1; $j++) {
 
  561                $cur_attr = $this->history_attrs[
$i][$j];
 
  562                $scrollback.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->history[
$i][$j]) ? $this->history[
$i][$j] : 
'');
 
  563                $last_attr = $this->history_attrs[
$i][$j];
 
  565            $scrollback.= 
"\r\n";
 
  567        $base_attr_cell = $this->base_attr_cell;
 
  568        $this->base_attr_cell = $last_attr;
 
  569        $scrollback.= $this->_getScreen();
 
  570        $this->base_attr_cell = $base_attr_cell;
 
  572        return '<pre width="' . ($this->max_x + 1) . 
'" style="color: white; background: black">' . $scrollback . 
'</span></pre>';
 
An exception for terminatinating execution or to throw for unit testing.
getHistory()
Returns the current screen and the x previous lines.
getScreen()
Returns the current screen.
appendString($source)
Appdend a string.
_processCoordinate($last_attr, $cur_attr, $char)
Returns the current coordinate without preformating.
__construct()
Default Constructor.
_getScreen()
Returns the current screen without preformating.
loadString($source)
Load a string.
setHistory($history)
Set the number of lines that should be logged past the terminal height.
setDimensions($x, $y)
Set terminal width and height.
_newLine()
Add a new line.