Internal rework pending editframe

This commit is contained in:
Deon George
2019-07-12 10:42:01 +07:00
parent 4f79a1a997
commit 264747e2f3
14 changed files with 611 additions and 428 deletions

View File

@@ -16,11 +16,11 @@ class Ansi extends AbstractParser {
* @param int $start
* @return bool|int
*/
private function findEOF(string $char,int $start)
private function findEOF(string $char,int $start,string $content)
{
for ($c=$start;$c <= strlen($this->content);$c++)
for ($c=$start;$c <= strlen($content);$c++)
{
if ($this->content{$c} != $char)
if ($content{$c} != $char)
return $c-$start;
}
@@ -32,7 +32,7 @@ class Ansi extends AbstractParser {
* @param int $offset
* @return string
*/
protected function parse($startline): string
protected function parse(int $startline,string $content,int $width): string
{
// Our starting coordinates
$x = 1;
@@ -40,10 +40,10 @@ class Ansi extends AbstractParser {
$output = '';
// Scan the frame for a field start
for ($c=0; $c<=strlen($this->content); $c++)
for ($c=0; $c<=strlen($content); $c++)
{
// If the frame is not big enough, fill it with spaces.
$byte = isset($this->content{$c}) ? $this->content{$c} : ' ';
$byte = isset($content{$c}) ? $content{$c} : ' ';
$advance = 0;
switch ($byte) {
@@ -58,7 +58,7 @@ class Ansi extends AbstractParser {
case ESC:
$advance = 1;
// Is the next byte something we know about
$nextbyte = isset($this->content{$c+$advance}) ? $this->content{$c+$advance} : ' ';
$nextbyte = isset($content{$c+$advance}) ? $content{$c+$advance} : ' ';
switch ($nextbyte) {
case '[':
@@ -68,7 +68,7 @@ class Ansi extends AbstractParser {
// Find our end CSI param
$matches = [];
$a = preg_match('/([0-9]+[;]?)+([a-zA-Z])/',$this->content,$matches,NULL,$c+$advance);
$a = preg_match('/([0-9]+[;]?)+([a-zA-Z])/',$content,$matches,NULL,$c+$advance);
if (! $a)
break;
@@ -76,6 +76,13 @@ class Ansi extends AbstractParser {
$advance += strlen($matches[0])-1;
$chars .= $matches[0];
if (! isset($this->frame_data[$y][$x]))
$this->frame_data[$y][$x] = '';
else
$this->frame_data[$y][$x] .= '|';
$this->frame_data[$y][$x] .= $matches[0];
switch ($matches[2]) {
// We ignore 'm' they are color CSIs
case 'm': break;
@@ -96,10 +103,11 @@ class Ansi extends AbstractParser {
break;
default:
$c--; // Allow for the original ESC
// Allow for the original ESC
$c--;
$advance++;
$fieldtype = ord($nextbyte)%128; // @todo Do we need the %128 for ANSI?
$fieldlength = $this->findEOF(chr($fieldtype),$c+2)+1;
$fieldtype = ord($nextbyte);
$fieldlength = $this->findEOF(chr($fieldtype),$c+2,$content)+1;
$byte = '';
@@ -122,6 +130,7 @@ class Ansi extends AbstractParser {
$x++;
}
$this->frame_content[$y][$x] = $byte;
$output .= $byte;
if ($advance) {
@@ -129,7 +138,7 @@ class Ansi extends AbstractParser {
$c += $advance;
}
if ($x > 80) {
if ($x > $width) {
$x = 1;
$y++;
}

View File

@@ -10,7 +10,7 @@ use App\Classes\Frame\Videotex as VideotexFrame;
class Videotex extends AbstractParser
{
protected function parse($startline): string
protected function parse(int $startline,string $content,int $width): string
{
// Our starting coordinates
$output = '';
@@ -32,13 +32,13 @@ class Videotex extends AbstractParser
$posn = $y*VideotexFrame::$frame_width+$x;
// If the frame is not big enough, fill it with spaces.
$byte = ord(isset($this->content{$posn}) ? $this->content{$posn} : ' ')%128;
$byte = ord(isset($content{$posn}) ? $content{$posn} : ' ')%128;
// Check for start-of-field
if ($byte == ord(ESC)) { // Esc designates start of field (Esc-K is end of edit)
$infield = TRUE;
$fieldlength = 1;
$fieldtype = ord(substr($this->content,$posn+1,1))%128;
$fieldtype = ord(substr($content,$posn+1,1))%128;
$output .= VideotexFrame::$if_filler;
} else {
@@ -107,8 +107,8 @@ class Videotex extends AbstractParser
}
// truncate end of lines @todo havent validated this code or used it?
if (isset($pageflags['tru']) && substr($this->content,$posn,40-$x) === str_repeat(' ',40-$x)) {
$output .= CR . LF;
if (isset($pageflags['tru']) && substr($content,$posn,$width-$x) === str_repeat(' ',$width-$x)) {
$output .= CR.LF;
break;
}