2018-12-13 13:02:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Classes;
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
/**
|
|
|
|
* The Frame Parser looks into frames for ESC codes that renders dynamic information
|
|
|
|
*/
|
2018-12-25 01:48:57 +00:00
|
|
|
abstract class Parser
|
2018-12-13 13:02:42 +00:00
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
// Fields in the frame
|
|
|
|
public $fields = [];
|
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
// Magic Fields that are pre-filled
|
|
|
|
protected $fieldmap = [
|
|
|
|
'a'=>'address#',
|
|
|
|
'd'=>'%date',
|
|
|
|
];
|
2019-07-12 03:42:01 +00:00
|
|
|
|
|
|
|
// Position array of frame control chars
|
|
|
|
protected $frame_data = [];
|
|
|
|
|
|
|
|
// Position array of frame chars
|
|
|
|
protected $frame_content = [];
|
2018-12-29 12:24:41 +00:00
|
|
|
|
2019-07-14 12:43:31 +00:00
|
|
|
// Parsed frame, ready to send to client
|
|
|
|
public $output = '';
|
2018-12-29 12:24:41 +00:00
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
public function __construct(string $content,int $width,int $startline=1)
|
2018-12-29 12:24:41 +00:00
|
|
|
{
|
|
|
|
$this->fields = collect();
|
2019-07-12 03:42:01 +00:00
|
|
|
$this->output = $this->parse($startline,$content,$width);
|
2018-12-29 12:24:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString(): string
|
|
|
|
{
|
2019-07-12 03:42:01 +00:00
|
|
|
return $this->output;
|
2018-12-29 12:24:41 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 12:19:41 +00:00
|
|
|
/**
|
|
|
|
* Return the character at a specific position
|
|
|
|
*
|
|
|
|
* @param int $x
|
|
|
|
* @param int $y
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function char(int $x,int $y): string
|
|
|
|
{
|
|
|
|
$y += 1;
|
|
|
|
|
|
|
|
return (isset($this->frame_content[$y]) AND isset($this->frame_content[$y][$x]))
|
|
|
|
? $this->frame_content[$y][$x]
|
|
|
|
: ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attr(int $x,int $y)
|
|
|
|
{
|
|
|
|
$y += 1;
|
|
|
|
|
|
|
|
return (isset($this->frame_data[$y]) AND isset($this->frame_data[$y][$x]))
|
|
|
|
? implode(';',$this->frame_data[$y][$x]).'m'
|
|
|
|
: '-';
|
|
|
|
}
|
|
|
|
|
2019-07-12 03:42:01 +00:00
|
|
|
abstract protected function parse(int $startline,string $content,int $width): string;
|
2018-12-13 13:02:42 +00:00
|
|
|
}
|